Skip to content

Commit

Permalink
Merge pull request #41 from Baldanos/bbio_gpio
Browse files Browse the repository at this point in the history
Direct PIN control mode added
  • Loading branch information
bvernoux committed Mar 2, 2016
2 parents 383bb0f + 2aac109 commit e9451c7
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
96 changes: 96 additions & 0 deletions hydrabus/hydrabus_bbio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{

Expand Down Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions hydrabus/hydrabus_bbio.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

//Hydrabus specific
#define BBIO_CAN 0b00001000
#define BBIO_PIN 0b00001001

#define BBIO_RESET_HW 0b00001111
#define BBIO_PWM 0b00010010
Expand Down Expand Up @@ -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);

0 comments on commit e9451c7

Please sign in to comment.