Read one pin and toggle another led
Port
Port:
General:
Post Build Variant Used: true
Config Variant: VariantPostBuild
...
PortContainer: "PortContainer_0"
General:
PortNumberOfPortPins: 2
PortPin: "D16_RED_LED"
PortPin Pcr: 112 # port pin D16 as output
PortPin Direction: PORT_PIN_OUT
PortPin Level Value: PORT_PIN_LEVEL_LOW #init value after reset
...
PortPin: "D3_SW2_BTN"
PortPin Pcr: 99 # port pin D3 as input
PortPin Direction: PORT_PIN_IN
PortPin PE: PullEnabled
...
Dio
Dio:
...
DioPort: "PORTD"
General:
DioPortId: 3
DioChannel: "D16_RED_LED"
General:
DioChannelId: 16
DioChannel: "D3_SW_BTN"
General:
DioChannelId: 3
...
main.c
#include "Mcu.h"
#include "Port.h"
#include "Dio.h"
void EcuM_Init( void );
int main( void )
{
EcuM_Init();
while(1)
{
/*Inquire the pin state where the button is connected*/
if( Dio_ReadChannal( DioConf_DioChannel_D3_SW_BTN ) == STD_ON )
{
Dio_FlipChannel( DioConf_DioChannel_D16_RED_LED );
}
/*dummy delay to avoid polling the btn to often*/
for( uint32 i = 0u ; i < 1000000u ; i++ );
}
return 0;
}
void EcuM_Init( void )
{
Mcu_Init( &Mcu_Config );
/* Initialize the clock tree with no PLL active*/
Mcu_InitClock( McuClockSettingConfig_0 );
Mcu_SetMode( McuModeSettingConf_0 );
/*Init ports D16 and E8*/
Port_Init( &Port_Config );
}