diff --git a/mcu/main.c b/mcu/main.c index 98c45bd..aafa7c8 100644 --- a/mcu/main.c +++ b/mcu/main.c @@ -7,20 +7,39 @@ const uint PIN_DIGIT_BASE = 18; const uint PIN_SEGMENT_BASE = 2; -const uint DIGITS = 4; +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(); - gpio_init(LED_PIN); - gpio_set_dir(LED_PIN, GPIO_OUT); + 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) { - gpio_put(LED_PIN, 0); - sleep_ms(250); - gpio_put(LED_PIN, 1); - puts("Hello World\n"); - sleep_ms(1000); + 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); + } } }