add VFD code

This commit is contained in:
King Kévin 2016-01-18 16:27:51 +01:00
parent 2eff94979e
commit 30638d643b
2 changed files with 54 additions and 3 deletions

49
main.c
View File

@ -56,11 +56,17 @@ static void clock_setup(void)
{
rcc_clock_setup_in_hse_8mhz_out_72mhz(); // use 8 MHz high speed external clock to generate 72 MHz internal clock
rcc_periph_clock_enable(LED_RCC); //enable clock for LED
rcc_periph_clock_enable(VFD_RCC); //enable clock for VFD
}
static void gpio_setup(void)
{
gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, LED_PIN); // set LED pin to 'output push-pull'
gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, LED_PIN); // set LED pin to 'output push-pull'
gpio_set_mode(VFD_PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, VFD_STR); // set VFD pin to 'output push-pull'
gpio_set_mode(VFD_PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, VFD_NLE); // set VFD pin to 'output push-pull'
gpio_set_mode(VFD_PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, VFD_CLK); // set VFD pin to 'output push-pull'
gpio_set_mode(VFD_PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, VFD_DIN); // set VFD pin to 'output push-pull'
}
int main(void)
@ -70,22 +76,59 @@ int main(void)
clock_setup(); // setup main clock
gpio_setup(); // setup main inputs/ouputs
usart_setup(); // setup USART (for printing)
cdcacm_setup(); // setup USB CDC ACM (for printing)
cdcacm_setup(); // setup USART (for printing)
setbuf(stdout, NULL); // set standard out buffer to NULL to immediately print
setbuf(stderr, NULL); // set standard error buffer to NULL to immediately print
printf("welcome to the STM32F1 CuVoodoo example code\n");
printf("welcome to the STM32F1 CuVoodoo display driver\n");
printf("sending VFD data\n");
gpio_set(VFD_PORT, VFD_STR); // disable HV output
gpio_clear(VFD_PORT, VFD_NLE); // do not latch data
gpio_set(VFD_PORT, VFD_CLK); // clock is idle high
bool vfd_transmit = false;
uint32_t vfd_data[3] = {~0,~0,~0};
uint8_t bit_flip = 0;
/* blink the LED with every transmitted character */
while (1) {
while (usart_received) { // echo every received character
gpio_toggle(LED_PORT, LED_PIN); // toggle LED
printf("%c",usart_getchar()); // transmit receive character
vfd_transmit = true;
}
while (cdcacm_received) { // echo every received character
gpio_toggle(LED_PORT, LED_PIN); // toggle LED
printf("%c",cdcacm_getchar()); // transmit receive character
vfd_transmit = true;
}
while (vfd_transmit) {
vfd_transmit = false;
/* send data to VFD (data valid on clock high) to 3x32 lines */
gpio_set(VFD_PORT, VFD_STR); // disable HV output
gpio_clear(VFD_PORT, VFD_NLE); // do not latch data
gpio_set(VFD_PORT, VFD_CLK); // clock is idle high
for (uint8_t i=0; i<3; i++) {
printf("%08lx ", vfd_data[i]);
for (uint8_t b=0; b<32; b++) {
gpio_clear(VFD_PORT, VFD_CLK);
if (vfd_data[i]&(1<<b)) {
gpio_set(VFD_PORT, VFD_DIN);
} else {
gpio_clear(VFD_PORT, VFD_DIN);
}
gpio_set(VFD_PORT, VFD_CLK);
}
vfd_data[i] = ~0;
}
gpio_set(VFD_PORT, VFD_NLE); // latch data
gpio_clear(VFD_PORT, VFD_STR); // enable HV output
printf("\n");
/* flip bit */
vfd_data[bit_flip/32] = ~(1<<(bit_flip%32));
bit_flip = (bit_flip+1)%(3*32);
}
__WFI(); // go to sleep
}

8
main.h
View File

@ -19,5 +19,13 @@
#define LED_PORT GPIOA
#define LED_PIN GPIO1
/* supertex HV518 vacuum fluorescent display pins */
#define VFD_RCC RCC_GPIOA
#define VFD_PORT GPIOA
#define VFD_STR GPIO4
#define VFD_NLE GPIO5
#define VFD_CLK GPIO6
#define VFD_DIN GPIO7
/* default output (i.e. for printf) */
int _write(int file, char *ptr, int len);