46 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
#include <stdio.h>
 | 
						|
 | 
						|
#include "hardware/gpio.h"
 | 
						|
#include "pico/stdlib.h"
 | 
						|
#include "pico/binary_info.h"
 | 
						|
 | 
						|
const uint PIN_DIGIT_BASE = 18;
 | 
						|
const uint PIN_SEGMENT_BASE = 2;
 | 
						|
 | 
						|
const uint N_DIGITS = 4;
 | 
						|
 | 
						|
uint8_t digit_states[4] = { 0b11001100, 0b11111111, 0b10101010, 0b00101001 };
 | 
						|
 | 
						|
void write_digit(uint8_t digit) {
 | 
						|
  const uint mask = (0xffffffff << PIN_SEGMENT_BASE) ^ (0xffffffff << PIN_SEGMENT_BASE + 8);
 | 
						|
  gpio_put_masked(mask, (~digit & 0xff) << PIN_SEGMENT_BASE);
 | 
						|
  gpio_put_masked(mask, digit << PIN_SEGMENT_BASE);
 | 
						|
}
 | 
						|
 | 
						|
int main() {
 | 
						|
  bi_decl(bi_program_description("qCLK driver."));
 | 
						|
 | 
						|
  stdio_init_all();
 | 
						|
 | 
						|
  for (uint i = PIN_DIGIT_BASE; i < PIN_DIGIT_BASE + N_DIGITS; i++) {
 | 
						|
    gpio_init(i);
 | 
						|
    gpio_set_dir(i, GPIO_OUT);
 | 
						|
    gpio_put(i, 0);
 | 
						|
  }
 | 
						|
  for (uint i = PIN_SEGMENT_BASE; i < PIN_SEGMENT_BASE + 8; i++) {
 | 
						|
    gpio_init(i);
 | 
						|
    gpio_set_dir(i, GPIO_OUT);
 | 
						|
  }
 | 
						|
  write_digit(0);
 | 
						|
 | 
						|
  while (1) {
 | 
						|
    for (uint i = 0; i < N_DIGITS; i++) {
 | 
						|
      uint prev = i == 0 ? N_DIGITS - 1 : i - 1;
 | 
						|
      gpio_put(PIN_DIGIT_BASE + prev, 0);
 | 
						|
      write_digit(digit_states[i]);
 | 
						|
      gpio_put(PIN_DIGIT_BASE + i, 1);
 | 
						|
      sleep_ms(1);
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 |