qclk/mcu/main.c

46 lines
1.1 KiB
C
Raw Normal View History

2024-05-09 20:29:14 +01:00
#include <stdio.h>
2024-05-11 00:57:43 +01:00
2024-05-09 20:29:14 +01:00
#include "hardware/gpio.h"
2024-05-11 00:57:43 +01:00
#include "pico/stdlib.h"
2024-05-09 20:29:14 +01:00
#include "pico/binary_info.h"
2024-05-11 00:57:43 +01:00
const uint PIN_DIGIT_BASE = 18;
const uint PIN_SEGMENT_BASE = 2;
2024-05-11 01:43:58 +01:00
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);
}
2024-05-09 20:29:14 +01:00
int main() {
2024-05-11 00:57:43 +01:00
bi_decl(bi_program_description("qCLK driver."));
2024-05-09 20:29:14 +01:00
stdio_init_all();
2024-05-11 01:43:58 +01:00
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);
2024-05-09 20:29:14 +01:00
while (1) {
2024-05-11 01:43:58 +01:00
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);
}
2024-05-09 20:29:14 +01:00
}
}