Skip to content

Commit

Permalink
LED Library reversed LED_BUILTIN
Browse files Browse the repository at this point in the history
On XMC1300 boards (Boot Kit and Sense2GO) The LED_Builtin is reversed to normal Arduino standard. On all other boards LED_BUILTIN works as per Arduino standard, but maybe different to XMC_LED_ON setting, this corrects both situations
  • Loading branch information
techpaul authored and jaenrig-ifx committed Jun 20, 2023
1 parent 51727bb commit 1d34055
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
10 changes: 8 additions & 2 deletions libraries/LED/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
**Author** | : | Paul Carpenter
| | | PC Services
| | | www.pcserviceselectronics.co.uk
**Version** | : | V1.0.3
**Updated** | : | August 2022
**Version** | : | V1.0.4
**Updated** | : | February 2023
Date | : | July 2018

Infineon XMC-for-Arduino LED Library, to assist in making board agnostic examples that
Expand Down Expand Up @@ -49,6 +49,7 @@ models of board so we end up with
XMC4700 Relax Kit | High| No | High
XMC4700 Relax Kit Lite | High| No | High

Library references a macro (#define) in pins_arduino.h, so on boards that have reversed to normal Arduino definition the library handles it and also handles when LED_BUILTIN is referenced and that board has different LED_BUILTIN operation to other LEDs. This way ALL references to ON or OFF using this library always works. (Added in V1.0.4)
[Back to top](#table-of-contents)
### LEDs on Different Boards
Matrix of available on board LED names or LED they map to, known currently.
Expand Down Expand Up @@ -76,6 +77,11 @@ operation this file must include a #define macro based on XMC_LED_ON as below -
/* On board LED is ON when digital output is 0, LOW, False, OFF */
#define XMC_LED_ON 0
~~~
Additionally there is an issue where LED_BUILTIN is not standard 1, HIGH, TRUE, ON is ON, so add extra define
~~~
/* On board LED_BUILTIN is NOT standard LED is ON when digital output is 0, LOW, False, OFF */
#define XMC_LED_BUILTIN_REVERSED 1
~~~
[Back to top](#table-of-contents)
## Known Limitations
This is meant for controlling hardware on board LEDs on the XMC1 and XMC4 series, if your
Expand Down
4 changes: 2 additions & 2 deletions libraries/LED/library.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name=LED
version=1.0.3
version=1.0.4
author=Infineon Technologies AG
maintainer=Infineon Technologies AG <www.infineon.com>
sentence=This library allows you to enable as well as control the on board LEDs of the XMC microcontrollers.
paragraph= This library allows you to enable as well as control the on boards LEDs on Infineon XMC boards, in a way that works across ANY board.
category=Other
url=https://github.com/Infineon/XMC-for-Arduino/tree/master/arm/libraries/LED
architectures=arm
architectures=xmc,arm

18 changes: 16 additions & 2 deletions libraries/LED/src/LED.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,28 @@ pinMode( pin, OUTPUT );
/* Set LED On for specified pin */
void LED::On( int pin )
{
digitalWrite( pin, XMC_LED_ON );
if( pin == LED_BUILTIN )
#ifdef XMC_LED_BUILTIN_REVERSED
digitalWrite( pin, false );
#else
digitalWrite( pin, true );
#endif
else
digitalWrite( pin, XMC_LED_ON );
}


/* Set LED Off for specified pin */
void LED::Off( int pin )
{
digitalWrite( pin, !XMC_LED_ON );
if( pin == LED_BUILTIN )
#ifdef XMC_LED_BUILTIN_REVERSED
digitalWrite( pin, true );
#else
digitalWrite( pin, false );
#endif
else
digitalWrite( pin, !XMC_LED_ON );
}


Expand Down
2 changes: 2 additions & 0 deletions variants/XMC1300/config/XMC1300_Boot_Kit/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

/* On board LED is ON when digital output is 0, LOW, False, OFF */
#define XMC_LED_ON 0
/* On board LED_BUILTIN is NOT standard LED is ON when digital output is 0, LOW, False, OFF */
#define XMC_LED_BUILTIN_REVERSED 1

// Following were defines now evaluated by compilation as const variables
// After definitions of associated mapping arrays
Expand Down
2 changes: 2 additions & 0 deletions variants/XMC1300/config/XMC1300_Sense2GoL/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

/* On board LED is ON when digital output is 0, LOW, False, OFF */
#define XMC_LED_ON 0
/* On board LED_BUILTIN is NOT standard LED is ON when digital output is 0, LOW, False, OFF */
#define XMC_LED_BUILTIN_REVERSED 1

// Following were defines now evaluated by compilation as const variables
// After definitions of associated mapping arrays
Expand Down

0 comments on commit 1d34055

Please sign in to comment.