X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=src%2Fstm-demo%2Fao_demo.c;h=93eb92f48c238e8d2ee698bf824cca5c80ec58b3;hp=fe7c69f2a4e8fac88416ca5c75aa94c23e9dbe34;hb=fda36e57205138f6c180a18b54956ea1682a5293;hpb=bd02349111ae0f39b320e6a10a330051ddc39fdf diff --git a/src/stm-demo/ao_demo.c b/src/stm-demo/ao_demo.c index fe7c69f2..93eb92f4 100644 --- a/src/stm-demo/ao_demo.c +++ b/src/stm-demo/ao_demo.c @@ -3,7 +3,8 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -20,40 +21,12 @@ #include #include #include +#include struct ao_task demo_task; static inline int min(int a, int b) { return a < b ? a : b; } -void -ao_demo(void) -{ - char message[] = "Hello, Mike & Bdale --- "; - char part[7]; - int i = 0; - int len = sizeof(message) - 1; - int first, second; - - part[6] = '\0'; - for (;;) { - ao_delay(AO_MS_TO_TICKS(150)); - first = min(6, len - i); - second = 6 - first; - memcpy(part, message + i, first); - memcpy(part + first, message, second); - ao_lcd_font_string(part); - if (++i >= len) - i = 0; - } -} - -void _close() { } -void _sbrk() { } -void _isatty() { } -void _lseek() { } -void _exit () { } -void _read () { } -void _fstat() { } #define AO_DMA_TEST_INDEX STM_DMA_INDEX(4) @@ -123,7 +96,7 @@ ao_i2c_write(void) { for (i = 0; i < 10; i++) { ao_i2c_get(0); if (ao_i2c_start(0, 0x55)) - ao_i2c_send(data, 4, 0, TRUE); + ao_i2c_send(data, 4, 0, true); else { printf ("i2c start failed\n"); ao_i2c_put(0); @@ -152,6 +125,7 @@ ao_temp (void) printf ("temp: %d\n", temp); } +#if 0 static void ao_event(void) { @@ -167,14 +141,41 @@ ao_event(void) } } +#endif -__code struct ao_cmds ao_demo_cmds[] = { +static uint8_t ao_blinking = 0; + +static void +ao_blink(void) +{ + for (;;) { + while (!ao_blinking) + ao_sleep(&ao_blinking); + while (ao_blinking) { + ao_led_toggle(AO_LED_BLUE|AO_LED_GREEN); + ao_delay(AO_MS_TO_TICKS(500)); + } + } +} + +static struct ao_task ao_blink_task; + +static void +ao_blink_toggle(void) +{ + ao_blinking = !ao_blinking; + ao_wakeup(&ao_blinking); +} + + +const struct ao_cmds ao_demo_cmds[] = { { ao_dma_test, "D\0DMA test" }, { ao_spi_write, "W\0SPI write" }, { ao_spi_read, "R\0SPI read" }, { ao_i2c_write, "i\0I2C write" }, { ao_temp, "t\0Show temp" }, - { ao_event, "e\0Monitor event queue" }, + { ao_blink_toggle, "b\0Toggle LED blinking" }, +/* { ao_event, "e\0Monitor event queue" }, */ { 0, NULL } }; @@ -183,23 +184,29 @@ main(void) { ao_clock_init(); - ao_serial_init(); + ao_task_init(); + + ao_led_init(); + ao_led_on(AO_LED_GREEN); + ao_led_off(AO_LED_BLUE); ao_timer_init(); ao_dma_init(); ao_cmd_init(); - ao_lcd_stm_init(); +// ao_lcd_stm_init(); // ao_lcd_font_init(); ao_spi_init(); - ao_i2c_init(); - ao_exti_init(); - ao_quadrature_init(); - ao_button_init(); +// ao_i2c_init(); +// ao_exti_init(); +// ao_quadrature_init(); +// ao_button_init(); + ao_storage_init(); - ao_timer_set_adc_interval(100); +// ao_timer_set_adc_interval(100); - ao_adc_init(); +// ao_adc_init(); ao_usb_init(); + ao_add_task(&ao_blink_task, ao_blink, "blink"); ao_cmd_register(&ao_demo_cmds[0]); ao_start_scheduler();