Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extended GPIO output functionality, PicoC and PIOS_GPIO #1628

Merged
merged 17 commits into from
Jun 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions flight/Modules/PicoC/picoc_library.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,47 @@ void SystemI2CWrite(struct ParseState *Parser, struct Value *ReturnValue, struct
}
#endif

#ifdef PIOS_INCLUDE_GPIO
/* void GPIOWrite(unsigned int, unsigned int): Writes/sets a general purpose output pin */
/*(unsigned int pin_num, unsigned int command)*/
/*unsigned int pin_num: Number of the defined GPIO pin from target/board-info/pios_board.h; starting from 0; user has to check if it is a input or output pin*/
/*unsigned int command: 0=reset_pin , 1=set_pin, 2=toggle_pin*/
void SystemGPIOWrite(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
if (Param[0]->Val->UnsignedInteger < PIOS_GPIO_NUM)
{
switch(Param[1]->Val->Integer) {
case 0:
PIOS_GPIO_Off(Param[0]->Val->UnsignedInteger);
break;
case 1:
PIOS_GPIO_On(Param[0]->Val->UnsignedInteger);
break;
case 2:
PIOS_GPIO_Toggle(Param[0]->Val->UnsignedInteger);
break;
}
}
}


/* void int GPIORead(unsigned int): Reads the value of a general purpose input pin */
/*(unsigned int pin_num)*/
/*unsigned int pin_num: Number of the defined GPIO pin from target/board-info/pios_board.h; starting from 0; user has to check if it is a input or output pin*/
void SystemGPIORead(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
if (Param[0]->Val->UnsignedInteger < PIOS_GPIO_NUM)
{
ReturnValue->Val->Integer = PIOS_GPIO_Read(Param[0]->Val->UnsignedInteger);
}
else
{
ReturnValue->Val->Integer = -1;
}
}
#endif


/* list of all library functions and their prototypes */
struct LibraryFunction PlatformLibrary_system[] =
{
Expand Down Expand Up @@ -648,6 +689,10 @@ struct LibraryFunction PlatformLibrary_system[] =
#ifdef PIOS_INCLUDE_I2C
{ SystemI2CRead, "int i2c_read(unsigned char,unsigned char, void *,unsigned int);" },
{ SystemI2CWrite, "int i2c_write(unsigned char,unsigned char, void *,unsigned int);" },
#endif
#ifdef PIOS_INCLUDE_GPIO
{ SystemGPIOWrite, "void GPIOWrite(unsigned int, unsigned int);" },
{ SystemGPIORead, "int GPIORead(unsigned int);" },
#endif
{ NULL, NULL }
};
Expand Down
13 changes: 11 additions & 2 deletions flight/PiOS/STM32F10x/pios_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void PIOS_GPIO_Enable(uint8_t Pin)
*/
void PIOS_GPIO_On(uint8_t Pin)
{
GPIO_PORT[Pin]->BRR = GPIO_PIN[Pin];
GPIO_SetBits(GPIO_PORT[Pin], GPIO_PIN[Pin]);
}

/**
Expand All @@ -81,7 +81,7 @@ void PIOS_GPIO_On(uint8_t Pin)
*/
void PIOS_GPIO_Off(uint8_t Pin)
{
GPIO_PORT[Pin]->BSRR = GPIO_PIN[Pin];
GPIO_ResetBits(GPIO_PORT[Pin], GPIO_PIN[Pin]);
}

/**
Expand All @@ -93,6 +93,15 @@ void PIOS_GPIO_Toggle(uint8_t Pin)
GPIO_PORT[Pin]->ODR ^= GPIO_PIN[Pin];
}

/**
* Read Pin value
* \param[in] Pin Pin Number
*/
uint8_t PIOS_GPIO_Read(uint8_t Pin)
{
return GPIO_ReadInputDataBit(GPIO_PORT[Pin], GPIO_PIN[Pin]);
}

#endif

/**
Expand Down
13 changes: 11 additions & 2 deletions flight/PiOS/STM32F30x/pios_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void PIOS_GPIO_Enable(uint8_t Pin)
*/
void PIOS_GPIO_On(uint8_t Pin)
{
GPIO_ResetBits(GPIO_PORT[Pin], GPIO_PIN[Pin]);
GPIO_SetBits(GPIO_PORT[Pin], GPIO_PIN[Pin]);
}

/**
Expand All @@ -81,7 +81,7 @@ void PIOS_GPIO_On(uint8_t Pin)
*/
void PIOS_GPIO_Off(uint8_t Pin)
{
GPIO_SetBits(GPIO_PORT[Pin], GPIO_PIN[Pin]);
GPIO_ResetBits(GPIO_PORT[Pin], GPIO_PIN[Pin]);
}

/**
Expand All @@ -93,6 +93,15 @@ void PIOS_GPIO_Toggle(uint8_t Pin)
GPIO_ToggleBits(GPIO_PORT[Pin], GPIO_PIN[Pin]);
}

/**
* Read Pin value
* \param[in] Pin Pin Number
*/
uint8_t PIOS_GPIO_Read(uint8_t Pin)
{
return GPIO_ReadInputDataBit(GPIO_PORT[Pin], GPIO_PIN[Pin]);
}

#endif

/**
Expand Down
13 changes: 11 additions & 2 deletions flight/PiOS/STM32F4xx/pios_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void PIOS_GPIO_Enable(uint8_t Pin)
*/
void PIOS_GPIO_On(uint8_t Pin)
{
GPIO_ResetBits(GPIO_PORT[Pin], GPIO_PIN[Pin]);
GPIO_SetBits(GPIO_PORT[Pin], GPIO_PIN[Pin]);
}

/**
Expand All @@ -80,7 +80,7 @@ void PIOS_GPIO_On(uint8_t Pin)
*/
void PIOS_GPIO_Off(uint8_t Pin)
{
GPIO_SetBits(GPIO_PORT[Pin], GPIO_PIN[Pin]);
GPIO_ResetBits(GPIO_PORT[Pin], GPIO_PIN[Pin]);
}

/**
Expand All @@ -92,6 +92,15 @@ void PIOS_GPIO_Toggle(uint8_t Pin)
GPIO_ToggleBits(GPIO_PORT[Pin], GPIO_PIN[Pin]);
}

/**
* Read Pin value
* \param[in] Pin Pin Number
*/
uint8_t PIOS_GPIO_Read(uint8_t Pin)
{
return GPIO_ReadInputDataBit(GPIO_PORT[Pin], GPIO_PIN[Pin]);
}

#endif

/**
Expand Down
1 change: 1 addition & 0 deletions flight/PiOS/inc/pios_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extern void PIOS_GPIO_Enable(uint8_t Pin);
extern void PIOS_GPIO_On(uint8_t Pin);
extern void PIOS_GPIO_Off(uint8_t Pin);
extern void PIOS_GPIO_Toggle(uint8_t Pin);
extern uint8_t PIOS_GPIO_Read(uint8_t Pin);

#endif /* PIOS_GPIO_H */

Expand Down
10 changes: 10 additions & 0 deletions flight/targets/quanton/board-info/pios_board.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,16 @@ extern uintptr_t pios_com_debug_id;
//-------------------------
#define PIOS_USB_ENABLED 1 /* Should remove all references to this */

//-------------------------
// GPIO
//-------------------------
// [0]: Output-> Quanton Buzzer Pin, with active driver connected to GND
// [1]: Output-> Quanton Battery Pin, take care of the voltage divider connected to this pin
// [2]-[9]: Input-> Quanton PWN IN Pins 1-8, take care of the RcvrPort configuration in GCS and that the Pins are configured with a PullUp Resistor
#define PIOS_GPIO_PORTS { GPIOA, GPIOC, GPIOA, GPIOC, GPIOC, GPIOC, GPIOA, GPIOB, GPIOA, GPIOA }
#define PIOS_GPIO_PINS { GPIO_Pin_4, GPIO_Pin_15, GPIO_Pin_10, GPIO_Pin_6, GPIO_Pin_7, GPIO_Pin_8, GPIO_Pin_15, GPIO_Pin_3, GPIO_Pin_0, GPIO_Pin_1 }
#define PIOS_GPIO_NUM 10

#endif /* STM3210E_INS_H_ */

/**
Expand Down
5 changes: 3 additions & 2 deletions flight/targets/quanton/fw/pios_board.c
Original file line number Diff line number Diff line change
Expand Up @@ -1444,9 +1444,10 @@ void PIOS_Board_Init(void) {
panic(9);
#endif /* PIOS_INCLUDE_FLASH */

//Set battery input pin to floating as long as it is unused
//Set battery input pin to output, because of the voltage divider usage as input is not useful
//Take care of the voltage divider connected to this pin
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
Expand Down
2 changes: 1 addition & 1 deletion flight/targets/quanton/fw/pios_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#define PIOS_INCLUDE_USB
#define PIOS_INCLUDE_USB_HID
#define PIOS_INCLUDE_USB_CDC
//#define PIOS_INCLUDE_GPIO
#define PIOS_INCLUDE_GPIO
#define PIOS_INCLUDE_EXTI
#define PIOS_INCLUDE_RTC
#define PIOS_INCLUDE_WDG
Expand Down