application: add BV I2C

This commit is contained in:
King Kévin 2018-03-11 17:52:20 +01:00
parent 07b4cb10cc
commit 9ba771b92e
1 changed files with 6 additions and 8 deletions

View File

@ -15,7 +15,7 @@
/** STM32F1 BusVoodoo application
* @file application.c
* @author King Kévin <kingkevin@cuvoodoo.info>
* @date 2016-2017
* @date 2016-2018
*/
/* standard libraries */
@ -39,11 +39,13 @@
#include "busvoodoo_oled.h" // OLED utilities
#include "busvoodoo_hiz.h" // BusVoodoo HiZ mode
#include "busvoodoo_uart.h" // BusVoodoo UART mode
#include "busvoodoo_i2c.h" // BusVoodoo I2C mode
/** all supported BusVoodoo modes */
static struct busvoodoo_mode_t* busvoodoo_modes[] = {
&busvoodoo_hiz_mode,
&busvoodoo_uart_mode,
&busvoodoo_i2c_mode,
};
/** current BusVoodoo mode */
@ -77,6 +79,8 @@ static void switch_mode(struct busvoodoo_mode_t* mode)
if (busvoodoo_mode) {
(*busvoodoo_mode->exit)(); // exit current mode
}
led_off(); // switch off LEDs
busvoodoo_safe_state(); // return to safe state
// reset pinout
for (uint8_t i=0; i<LENGTH(busvoodoo_global_pinout_rscan); i++) {
busvoodoo_global_pinout_rscan[i] = NULL;
@ -84,8 +88,6 @@ static void switch_mode(struct busvoodoo_mode_t* mode)
for (uint8_t i=0; i<LENGTH(busvoodoo_global_pinout_io); i++) {
busvoodoo_global_pinout_io[i] = NULL;
}
// reset OLED
busvoodoo_safe_state(); // return to safe state
busvoodoo_oled_clear(); // clear OLED display buffer
busvoodoo_oled_update(); // update OLED display
if (NULL==mode) { // no mode provided
@ -194,11 +196,7 @@ static void command_mode(void* argument)
bool mode_found = false; // to know if we found the matching mode
for (uint8_t i=0; i<LENGTH(busvoodoo_modes); i++) { // go through all modes
if (0==strcmp(argument, busvoodoo_modes[i]->name)) { // check for corresponding mode
(*busvoodoo_mode->exit)(); // exit current mode
led_off(); // switch off LEDs
busvoodoo_mode = busvoodoo_modes[i]; // set matching mode as current mode
busvoodoo_mode_complete = (*busvoodoo_mode->setup)(&terminal_prefix, NULL); // start setup
terminal_send(0); // update the terminal prompt
switch_mode(busvoodoo_modes[i]); // switch to mode
mode_found = true; // remember we found the mode
break; // stop searching for mode
}