AP_HAL_VRBRAIN: added management for external relay 1 and 2

This commit is contained in:
Emile Castelnuovo 2014-08-21 17:35:41 +02:00 committed by Randy Mackay
parent 07420521ab
commit 8e42b21bab
2 changed files with 45 additions and 7 deletions

View File

@ -44,22 +44,23 @@ void VRBRAINGPIO::init()
if (ioctl(_led_fd, LED_OFF, LED_GREEN) != 0) { if (ioctl(_led_fd, LED_OFF, LED_GREEN) != 0) {
hal.console->printf("GPIO: Unable to setup GPIO LED GREEN\n"); hal.console->printf("GPIO: Unable to setup GPIO LED GREEN\n");
} }
#if !defined(CONFIG_ARCH_BOARD_VRHERO_V10) #if defined(LED_EXT1)
if (ioctl(_led_fd, LED_OFF, LED_EXT1) != 0) { if (ioctl(_led_fd, LED_OFF, LED_EXT1) != 0) {
hal.console->printf("GPIO: Unable to setup GPIO LED EXT 1\n"); hal.console->printf("GPIO: Unable to setup GPIO LED EXT 1\n");
} }
#endif #endif
#if !defined(CONFIG_ARCH_BOARD_VRHERO_V10) #if defined(LED_EXT2)
if (ioctl(_led_fd, LED_OFF, LED_EXT2) != 0) { if (ioctl(_led_fd, LED_OFF, LED_EXT2) != 0) {
hal.console->printf("GPIO: Unable to setup GPIO LED EXT 2\n"); hal.console->printf("GPIO: Unable to setup GPIO LED EXT 2\n");
} }
#endif #endif
#if !defined(CONFIG_ARCH_BOARD_VRHERO_V10) && !defined(CONFIG_ARCH_BOARD_VRUBRAIN_V51) #if defined(LED_EXT3)
if (ioctl(_led_fd, LED_OFF, LED_EXT3) != 0) { if (ioctl(_led_fd, LED_OFF, LED_EXT3) != 0) {
hal.console->printf("GPIO: Unable to setup GPIO LED EXT 3\n"); hal.console->printf("GPIO: Unable to setup GPIO LED EXT 3\n");
} }
#endif #endif
#if defined(BUZZER_EXT)
_buzzer_fd = open(BUZZER_DEVICE_PATH, O_RDWR); _buzzer_fd = open(BUZZER_DEVICE_PATH, O_RDWR);
if (_buzzer_fd == -1) { if (_buzzer_fd == -1) {
hal.scheduler->panic("Unable to open " BUZZER_DEVICE_PATH); hal.scheduler->panic("Unable to open " BUZZER_DEVICE_PATH);
@ -67,6 +68,15 @@ void VRBRAINGPIO::init()
if (ioctl(_buzzer_fd, BUZZER_OFF, BUZZER_EXT) != 0) { if (ioctl(_buzzer_fd, BUZZER_OFF, BUZZER_EXT) != 0) {
hal.console->printf("GPIO: Unable to setup GPIO BUZZER\n"); hal.console->printf("GPIO: Unable to setup GPIO BUZZER\n");
} }
#endif
#if defined(GPIO_GPIO0_OUTPUT)
stm32_configgpio(GPIO_GPIO0_OUTPUT);
#endif
#if defined(GPIO_GPIO1_OUTPUT)
stm32_configgpio(GPIO_GPIO1_OUTPUT);
#endif
} }
void VRBRAINGPIO::pinMode(uint8_t pin, uint8_t output) void VRBRAINGPIO::pinMode(uint8_t pin, uint8_t output)
@ -85,6 +95,16 @@ uint8_t VRBRAINGPIO::read(uint8_t pin)
{ {
switch (pin) { switch (pin) {
case EXTERNAL_RELAY1_PIN:
#if defined(GPIO_GPIO0_OUTPUT)
return (stm32_gpioread(GPIO_GPIO0_OUTPUT))?HIGH:LOW;
#endif
break;
case EXTERNAL_RELAY2_PIN:
#if defined(GPIO_GPIO1_OUTPUT)
return (stm32_gpioread(GPIO_GPIO1_OUTPUT))?HIGH:LOW;
#endif
break;
} }
return LOW; return LOW;
} }
@ -118,7 +138,7 @@ void VRBRAINGPIO::write(uint8_t pin, uint8_t value)
break; break;
case EXTERNAL_LED_GPS: case EXTERNAL_LED_GPS:
#if !defined(CONFIG_ARCH_BOARD_VRHERO_V10) #if defined(LED_EXT1)
if (value == LOW) { if (value == LOW) {
ioctl(_led_fd, LED_OFF, LED_EXT1); ioctl(_led_fd, LED_OFF, LED_EXT1);
} else { } else {
@ -128,7 +148,7 @@ void VRBRAINGPIO::write(uint8_t pin, uint8_t value)
break; break;
case EXTERNAL_LED_ARMED: case EXTERNAL_LED_ARMED:
#if !defined(CONFIG_ARCH_BOARD_VRHERO_V10) #if defined(LED_EXT2)
if (value == LOW) { if (value == LOW) {
ioctl(_led_fd, LED_OFF, LED_EXT2); ioctl(_led_fd, LED_OFF, LED_EXT2);
} else { } else {
@ -144,12 +164,26 @@ void VRBRAINGPIO::write(uint8_t pin, uint8_t value)
break; break;
case BUZZER_PIN: case BUZZER_PIN:
#if defined(BUZZER_EXT)
if (value == LOW) { if (value == LOW) {
ioctl(_buzzer_fd, BUZZER_OFF, BUZZER_EXT); ioctl(_buzzer_fd, BUZZER_OFF, BUZZER_EXT);
} else { } else {
ioctl(_buzzer_fd, BUZZER_ON, BUZZER_EXT); ioctl(_buzzer_fd, BUZZER_ON, BUZZER_EXT);
} }
#endif
break; break;
case EXTERNAL_RELAY1_PIN:
#if defined(GPIO_GPIO0_OUTPUT)
stm32_gpiowrite(GPIO_GPIO0_OUTPUT, (value==HIGH));
#endif
break;
case EXTERNAL_RELAY2_PIN:
#if defined(GPIO_GPIO1_OUTPUT)
stm32_gpiowrite(GPIO_GPIO1_OUTPUT, (value==HIGH));
#endif
break;
} }
} }
@ -170,13 +204,13 @@ void VRBRAINGPIO::toggle(uint8_t pin)
break; break;
case EXTERNAL_LED_GPS: case EXTERNAL_LED_GPS:
#if !defined(CONFIG_ARCH_BOARD_VRHERO_V10) #if defined(LED_EXT1)
ioctl(_led_fd, LED_TOGGLE, LED_EXT1); ioctl(_led_fd, LED_TOGGLE, LED_EXT1);
#endif #endif
break; break;
case EXTERNAL_LED_ARMED: case EXTERNAL_LED_ARMED:
#if !defined(CONFIG_ARCH_BOARD_VRHERO_V10) #if defined(LED_EXT2)
ioctl(_led_fd, LED_TOGGLE, LED_EXT2); ioctl(_led_fd, LED_TOGGLE, LED_EXT2);
#endif #endif
break; break;
@ -190,7 +224,9 @@ void VRBRAINGPIO::toggle(uint8_t pin)
break; break;
case BUZZER_PIN: case BUZZER_PIN:
#if defined(BUZZER_EXT)
ioctl(_buzzer_fd, BUZZER_TOGGLE, BUZZER_EXT); ioctl(_buzzer_fd, BUZZER_TOGGLE, BUZZER_EXT);
#endif
break; break;
default: default:

View File

@ -13,6 +13,8 @@
# define EXTERNAL_LED_MOTOR1 30 # define EXTERNAL_LED_MOTOR1 30
# define EXTERNAL_LED_MOTOR2 31 # define EXTERNAL_LED_MOTOR2 31
# define BUZZER_PIN 32 # define BUZZER_PIN 32
# define EXTERNAL_RELAY1_PIN 33
# define EXTERNAL_RELAY2_PIN 34
# define HAL_GPIO_LED_ON HIGH # define HAL_GPIO_LED_ON HIGH
# define HAL_GPIO_LED_OFF LOW # define HAL_GPIO_LED_OFF LOW