Just in between the overview, a small off road let say, of the proof of concepts and building blocks I want to present a small piece of code needed to test our final design. I will dedicate this intermidiate topic to cover some small integrations tests I wrote using the firmware libraries. Refer to my dimmers blog to see what we actually want to test about here. As the code snippets are pretty simple I will add them here anyway because the intends are not of much importance.
(still hoping there will be a proper intend and tab support on these blogger forums one day)
Hardware to test
- 6 inputs
- 6 outputs triac/led
- 4 dip switches
- 1 main led
Test Purposes
- 6 outputs triac/led
- 4 dip switches
- 1 main led
Test Purposes
- Every button that goes low ( can be easly inverted with define ) toggles the triac/led output such that button0 toggles led0 and so on ...
- Every DIP switch of four that goes low ( can be easly inverted with define ) toggles the main led solely.
Here you can see how easy and quit readible the code can be written using the high level init structures of the firmware:
GpioDef gx_gpios[]={
//******************* PORT A
{GPIO_Pin_1, GPIO_Speed_50MHz, GPIO_Mode_AIN, GPIOA}, /** zero cross **/
//******************* PORT B
{GPIO_Pin_6, GPIO_Speed_50MHz, GPIO_Mode_Out_OD, GPIOB}, /** i2c1 scl **/
{GPIO_Pin_7, GPIO_Speed_50MHz, GPIO_Mode_Out_OD, GPIOB}, /** i2c1 sda **/
{GPIO_Pin_10, GPIO_Speed_50MHz, GPIO_Mode_Out_OD, GPIOB}, /** i2c2 scl **/
{GPIO_Pin_11, GPIO_Speed_50MHz, GPIO_Mode_Out_OD, GPIOB}, /** i2c2 sda **/
{GPIO_Pin_12, GPIO_Speed_2MHz, GPIO_Mode_IPU, GPIOB}, /** dip 1 **/
{GPIO_Pin_13, GPIO_Speed_2MHz, GPIO_Mode_IPU, GPIOB}, /** dip 2 **/
{GPIO_Pin_14, GPIO_Speed_2MHz, GPIO_Mode_IPU, GPIOB}, /** dip 3 **/
{GPIO_Pin_15, GPIO_Speed_2MHz, GPIO_Mode_IPU, GPIOB}, /** dip 4 **/
//******************* PORT C
{GPIO_Pin_0, GPIO_Speed_2MHz, GPIO_Mode_IPU, GPIOC}, /** button 1 **/
{GPIO_Pin_1, GPIO_Speed_2MHz, GPIO_Mode_IPU, GPIOC}, /** button 2 **/
{GPIO_Pin_2, GPIO_Speed_2MHz, GPIO_Mode_IPU, GPIOC}, /** button 3 **/
{GPIO_Pin_3, GPIO_Speed_2MHz, GPIO_Mode_IPU, GPIOC}, /** button 4 **/
{GPIO_Pin_4, GPIO_Speed_2MHz, GPIO_Mode_IPU, GPIOC}, /** button 5 **/
{GPIO_Pin_5, GPIO_Speed_2MHz, GPIO_Mode_IPU, GPIOC}, /** button 6 **/
{GPIO_Pin_6, GPIO_Speed_50MHz, GPIO_Mode_Out_PP, GPIOC}, /** triac 1 **/
{GPIO_Pin_7, GPIO_Speed_50MHz, GPIO_Mode_Out_PP, GPIOC}, /** triac 2 **/
{GPIO_Pin_8, GPIO_Speed_50MHz, GPIO_Mode_Out_PP, GPIOC}, /** triac 3 **/
{GPIO_Pin_9, GPIO_Speed_50MHz, GPIO_Mode_Out_PP, GPIOC}, /** triac 4 **/
{GPIO_Pin_10, GPIO_Speed_50MHz, GPIO_Mode_Out_PP, GPIOC}, /** triac 5 **/
{GPIO_Pin_11, GPIO_Speed_50MHz, GPIO_Mode_Out_PP, GPIOC}, /** triac 6 **/
{GPIO_Pin_12, GPIO_Speed_50MHz, GPIO_Mode_Out_PP, GPIOC}, /** main led **/
};
//******************* PORT A
{GPIO_Pin_1, GPIO_Speed_50MHz, GPIO_Mode_AIN, GPIOA}, /** zero cross **/
//******************* PORT B
{GPIO_Pin_6, GPIO_Speed_50MHz, GPIO_Mode_Out_OD, GPIOB}, /** i2c1 scl **/
{GPIO_Pin_7, GPIO_Speed_50MHz, GPIO_Mode_Out_OD, GPIOB}, /** i2c1 sda **/
{GPIO_Pin_10, GPIO_Speed_50MHz, GPIO_Mode_Out_OD, GPIOB}, /** i2c2 scl **/
{GPIO_Pin_11, GPIO_Speed_50MHz, GPIO_Mode_Out_OD, GPIOB}, /** i2c2 sda **/
{GPIO_Pin_12, GPIO_Speed_2MHz, GPIO_Mode_IPU, GPIOB}, /** dip 1 **/
{GPIO_Pin_13, GPIO_Speed_2MHz, GPIO_Mode_IPU, GPIOB}, /** dip 2 **/
{GPIO_Pin_14, GPIO_Speed_2MHz, GPIO_Mode_IPU, GPIOB}, /** dip 3 **/
{GPIO_Pin_15, GPIO_Speed_2MHz, GPIO_Mode_IPU, GPIOB}, /** dip 4 **/
//******************* PORT C
{GPIO_Pin_0, GPIO_Speed_2MHz, GPIO_Mode_IPU, GPIOC}, /** button 1 **/
{GPIO_Pin_1, GPIO_Speed_2MHz, GPIO_Mode_IPU, GPIOC}, /** button 2 **/
{GPIO_Pin_2, GPIO_Speed_2MHz, GPIO_Mode_IPU, GPIOC}, /** button 3 **/
{GPIO_Pin_3, GPIO_Speed_2MHz, GPIO_Mode_IPU, GPIOC}, /** button 4 **/
{GPIO_Pin_4, GPIO_Speed_2MHz, GPIO_Mode_IPU, GPIOC}, /** button 5 **/
{GPIO_Pin_5, GPIO_Speed_2MHz, GPIO_Mode_IPU, GPIOC}, /** button 6 **/
{GPIO_Pin_6, GPIO_Speed_50MHz, GPIO_Mode_Out_PP, GPIOC}, /** triac 1 **/
{GPIO_Pin_7, GPIO_Speed_50MHz, GPIO_Mode_Out_PP, GPIOC}, /** triac 2 **/
{GPIO_Pin_8, GPIO_Speed_50MHz, GPIO_Mode_Out_PP, GPIOC}, /** triac 3 **/
{GPIO_Pin_9, GPIO_Speed_50MHz, GPIO_Mode_Out_PP, GPIOC}, /** triac 4 **/
{GPIO_Pin_10, GPIO_Speed_50MHz, GPIO_Mode_Out_PP, GPIOC}, /** triac 5 **/
{GPIO_Pin_11, GPIO_Speed_50MHz, GPIO_Mode_Out_PP, GPIOC}, /** triac 6 **/
{GPIO_Pin_12, GPIO_Speed_50MHz, GPIO_Mode_Out_PP, GPIOC}, /** main led **/
};
Main routine
Kept pretty easy to only test the basics here:
#define PUSHED (0)
#define ACTIVE (0)
#define ACTIVE (0)
RccInit();
GpioInit();
GpioClockSet();
GpioInit();
GpioClockSet();
while (1)
{
// INTEGRATIONS TEST input/output
// toggle in I/O sequence button0-5 led/triac0-5 if ( GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_0) == PUSHED ){
GPIO_WriteBit(GPIOC, GPIO_Pin_6, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_6))));
}
if ( GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_1) == PUSHED ){
GPIO_WriteBit(GPIOC, GPIO_Pin_7, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_7))));
}
if ( GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_2) == PUSHED ){
GPIO_WriteBit(GPIOC, GPIO_Pin_8, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_8))));
}
if ( GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_3) == PUSHED ){
GPIO_WriteBit(GPIOC, GPIO_Pin_9, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_9))));
}
if ( GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_4) == PUSHED ){
GPIO_WriteBit(GPIOC, GPIO_Pin_10, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_10))));
}
if ( GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_5) == PUSHED ){
GPIO_WriteBit(GPIOC, GPIO_Pin_11, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_11))));
}
// INTEGRATIONS TEST DIP
// toggle main led when one of 4 dip is active
if ( GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_12) == ACTIVE ){
GPIO_WriteBit(GPIOC, GPIO_Pin_12, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_12))));
}
if ( GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_13) == ACTIVE ){
GPIO_WriteBit(GPIOC, GPIO_Pin_12, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_12))));
}
if ( GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_14) == ACTIVE ){
GPIO_WriteBit(GPIOC, GPIO_Pin_12, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_12))));
}
if ( GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_15) == ACTIVE){
GPIO_WriteBit(GPIOC, GPIO_Pin_12, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_12))));
}
}
}
{
// INTEGRATIONS TEST input/output
// toggle in I/O sequence button0-5 led/triac0-5 if ( GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_0) == PUSHED ){
GPIO_WriteBit(GPIOC, GPIO_Pin_6, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_6))));
}
if ( GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_1) == PUSHED ){
GPIO_WriteBit(GPIOC, GPIO_Pin_7, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_7))));
}
if ( GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_2) == PUSHED ){
GPIO_WriteBit(GPIOC, GPIO_Pin_8, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_8))));
}
if ( GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_3) == PUSHED ){
GPIO_WriteBit(GPIOC, GPIO_Pin_9, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_9))));
}
if ( GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_4) == PUSHED ){
GPIO_WriteBit(GPIOC, GPIO_Pin_10, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_10))));
}
if ( GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_5) == PUSHED ){
GPIO_WriteBit(GPIOC, GPIO_Pin_11, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_11))));
}
// INTEGRATIONS TEST DIP
// toggle main led when one of 4 dip is active
if ( GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_12) == ACTIVE ){
GPIO_WriteBit(GPIOC, GPIO_Pin_12, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_12))));
}
if ( GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_13) == ACTIVE ){
GPIO_WriteBit(GPIOC, GPIO_Pin_12, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_12))));
}
if ( GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_14) == ACTIVE ){
GPIO_WriteBit(GPIOC, GPIO_Pin_12, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_12))));
}
if ( GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_15) == ACTIVE){
GPIO_WriteBit(GPIOC, GPIO_Pin_12, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_12))));
}
}
}