From 2aac1090df88bbdfda023f0fb0fb398f3e5aa311 Mon Sep 17 00:00:00 2001 From: Baldanos Date: Wed, 2 Mar 2016 23:18:22 +0100 Subject: [PATCH] Direct PIN control mode added --- hydrabus/hydrabus_bbio.c | 96 ++++++++++++++++++++++++++++++++++++++++ hydrabus/hydrabus_bbio.h | 10 +++++ 2 files changed, 106 insertions(+) diff --git a/hydrabus/hydrabus_bbio.c b/hydrabus/hydrabus_bbio.c index 50980f33..2d9187d6 100644 --- a/hydrabus/hydrabus_bbio.c +++ b/hydrabus/hydrabus_bbio.c @@ -28,6 +28,7 @@ #include "bsp_spi.h" #include "bsp_can.h" #include "hydrabus_mode_jtag.h" +#include "bsp_gpio.h" static void print_raw_uint32(t_hydra_console *con, uint32_t num) { @@ -335,6 +336,97 @@ static void bbio_mode_can(t_hydra_console *con) } } + +static void bbio_mode_pin(t_hydra_console *con) +{ + uint8_t bbio_subcommand; + + uint8_t rx_buff, i, reconfig; + uint16_t data; + + uint32_t pin_mode[8]; + uint32_t pin_pull[8]; + + for(i=0; i<8; i++){ + pin_pull[i] = MODE_CONFIG_DEV_GPIO_NOPULL; + pin_pull[i] = MODE_CONFIG_DEV_GPIO_IN; + bsp_gpio_init(BSP_GPIO_PORTA, i, pin_mode[i], pin_pull[i]); + } + + while (true) { + if(chSequentialStreamRead(con->sdu, &bbio_subcommand, 1) == 1) { + switch(bbio_subcommand) { + case BBIO_RESET: + return; + case BBIO_PIN_READ: + data = bsp_gpio_port_read(BSP_GPIO_PORTA); + cprintf(con, "\x01%c", data & 0xff); + break; + case BBIO_PIN_NOPULL: + chSequentialStreamRead(con->sdu, &rx_buff, 1); + for(i=0; i<8; i++){ + if((rx_buff>>i)&1){ + pin_pull[i] = MODE_CONFIG_DEV_GPIO_NOPULL; + } + } + reconfig = 1; + cprint(con, "\x01", 1); + break; + case BBIO_PIN_PULLUP: + chSequentialStreamRead(con->sdu, &rx_buff, 1); + for(i=0; i<8; i++){ + if((rx_buff>>i)&1){ + pin_pull[i] = MODE_CONFIG_DEV_GPIO_PULLUP; + } + } + reconfig = 1; + cprint(con, "\x01", 1); + break; + case BBIO_PIN_PULLDOWN: + chSequentialStreamRead(con->sdu, &rx_buff, 1); + for(i=0; i<8; i++){ + if((rx_buff>>i)&1){ + pin_pull[i] = MODE_CONFIG_DEV_GPIO_PULLDOWN; + } + } + reconfig = 1; + cprint(con, "\x01", 1); + break; + case BBIO_PIN_MODE: + chSequentialStreamRead(con->sdu, &rx_buff, 1); + for(i=0; i<8; i++){ + if((rx_buff>>i)&1){ + pin_pull[i] = MODE_CONFIG_DEV_GPIO_IN; + }else{ + pin_pull[i] = MODE_CONFIG_DEV_GPIO_OUT_PUSHPULL; + } + } + reconfig = 1; + cprint(con, "\x01", 1); + break; + case BBIO_PIN_WRITE: + chSequentialStreamRead(con->sdu, &rx_buff, 1); + for(i=0; i<8; i++){ + if((data>>i)&1){ + bsp_gpio_set(BSP_GPIO_PORTA, i); + }else{ + bsp_gpio_clr(BSP_GPIO_PORTA, i); + } + } + cprint(con, "\x01", 1); + break; + } + if(reconfig == 1) { + for(i=0; i<8; i++){ + bsp_gpio_init(BSP_GPIO_PORTA, i, + pin_mode[i], pin_pull[i]); + } + reconfig = 0; + } + } + } +} + int cmd_bbio(t_hydra_console *con) { @@ -372,6 +464,10 @@ int cmd_bbio(t_hydra_console *con) cprint(con, "CAN1", 4); bbio_mode_can(con); break; + case BBIO_PIN: + cprint(con, "PIN1", 4); + bbio_mode_pin(con); + break; case BBIO_RESET_HW: return TRUE; default: diff --git a/hydrabus/hydrabus_bbio.h b/hydrabus/hydrabus_bbio.h index d76d7cca..5c9d4f63 100644 --- a/hydrabus/hydrabus_bbio.h +++ b/hydrabus/hydrabus_bbio.h @@ -29,6 +29,7 @@ //Hydrabus specific #define BBIO_CAN 0b00001000 +#define BBIO_PIN 0b00001001 #define BBIO_RESET_HW 0b00001111 #define BBIO_PWM 0b00010010 @@ -64,5 +65,14 @@ #define BBIO_CAN_FILTER 0b00000110 #define BBIO_CAN_WRITE 0b00001000 +/* + * PIN control-specific commands + */ +#define BBIO_PIN_READ 0b00000010 +#define BBIO_PIN_MODE 0b00000011 +#define BBIO_PIN_NOPULL 0b00000100 +#define BBIO_PIN_PULLUP 0b00000101 +#define BBIO_PIN_PULLDOWN 0b00000110 +#define BBIO_PIN_WRITE 0b00001000 int cmd_bbio(t_hydra_console *con);