split out to esp32 and samd targets
This commit is contained in:
parent
27b1bac061
commit
6a3d159a72
18 changed files with 374 additions and 0 deletions
16
samd/#platformio.ini#
Normal file
16
samd/#platformio.ini#
Normal file
|
@ -0,0 +1,16 @@
|
|||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:samd21g18a]
|
||||
platform = atmelsam
|
||||
board = samd21g18a
|
||||
framework = arduino
|
||||
|
||||
[env:atmel
|
1
samd/.gitignore
vendored
Normal file
1
samd/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
.pio
|
39
samd/include/README
Normal file
39
samd/include/README
Normal file
|
@ -0,0 +1,39 @@
|
|||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the usual convention is to give header files names that end with `.h'.
|
||||
It is most portable to use only letters, digits, dashes, and underscores in
|
||||
header file names, and at most one dot.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
64
samd/include/RgbDriver.h
Normal file
64
samd/include/RgbDriver.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* rgbDriver.h - Library for controlling the TI LT5024 RGB LED driver on the BSides Badge 2020
|
||||
* Reference: https://www.ti.com/lit/ds/symlink/lp5024.pdf
|
||||
* Created by Jordan Johnson, 23 February 2020
|
||||
*/
|
||||
|
||||
#ifndef RGB_DRIVER_H_
|
||||
#define RGB_DRIVER_H_
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
class RgbDriver
|
||||
{
|
||||
public:
|
||||
// Set the slave address of the LP5024 driver
|
||||
RgbDriver(char address);
|
||||
// Set Chip_EN=0 to enter STANDBY mode
|
||||
int selectStandbyMode();
|
||||
// Set Chip_EN=1 to enter normal mode
|
||||
int selectNormalMode();
|
||||
// Reset the LP5024
|
||||
int reset();
|
||||
// Set the LP5024 configuration
|
||||
int setDeviceConfig(bool Log_Scale_EN,
|
||||
bool Power_Save_EN,
|
||||
bool Auto_Incr_EN,
|
||||
bool PWM_Dithering_EN,
|
||||
bool Max_Current_Option,
|
||||
bool LED_Global_Off);
|
||||
// Enable or disable individual LEDs
|
||||
int setLedConfig(bool LED7_Bank_EN,
|
||||
bool LED6_Bank_EN,
|
||||
bool LED5_Bank_EN,
|
||||
bool LED4_Bank_EN,
|
||||
bool LED3_Bank_EN,
|
||||
bool LED2_Bank_EN,
|
||||
bool LED1_Bank_EN,
|
||||
bool LED0_Bank_EN);
|
||||
// Set the brightness for all LEDs
|
||||
int setBankBrightness(char bank_brightness);
|
||||
// Set the colour for all LEDs
|
||||
int setBankColour(char red, char green, char blue);
|
||||
// Set the brightness for an individual LED
|
||||
int setLedBrightness(char led, char brightness);
|
||||
// Set the colour for an individual LED
|
||||
int setLedColour(char led, char red, char green, char blue);
|
||||
private:
|
||||
// Transmit data to the LP5025 via I2C
|
||||
int transmit(char addr, char data);
|
||||
|
||||
// Address registers
|
||||
const char DEVICE_CONFIG0 = 0x00;
|
||||
const char DEVICE_CONFIG1 = 0x01;
|
||||
const char LED_CONFIG0 = 0x02;
|
||||
const char BANK_BRIGHTNESS = 0x03;
|
||||
const char BANK_A_COLOR = 0x04;
|
||||
const char BANK_B_COLOR = 0x05;
|
||||
const char BANK_C_COLOR = 0x06;
|
||||
const char RESET = 0x027;
|
||||
// The address of the LP5024
|
||||
char slaveAddress;
|
||||
};
|
||||
|
||||
#endif // RGB_DRIVER_H_
|
46
samd/lib/README
Normal file
46
samd/lib/README
Normal file
|
@ -0,0 +1,46 @@
|
|||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into executable file.
|
||||
|
||||
The source code of each library should be placed in a an own separate directory
|
||||
("lib/your_library_name/[here are source files]").
|
||||
|
||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- README --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
and a contents of `src/main.c`:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
19
samd/platformio.ini
Normal file
19
samd/platformio.ini
Normal file
|
@ -0,0 +1,19 @@
|
|||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:samd21g18a]
|
||||
platform = atmelsam
|
||||
board = samd21g18a
|
||||
framework = arduino
|
||||
|
||||
[env:mkrzero]
|
||||
platform = atmelsam
|
||||
board = mkrzero
|
||||
framework = arduino
|
127
samd/src/RgbDriver.cpp
Normal file
127
samd/src/RgbDriver.cpp
Normal file
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* rgbDriver.h - Library for controlling the TI LT5024 RGB LED driver on the BSides Badge 2020
|
||||
* Reference: https://www.ti.com/lit/ds/symlink/lp5024.pdf
|
||||
* Created by Jordan Johnson, 23 February 2020
|
||||
*/
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Wire.h"
|
||||
#include "RgbDriver.h"
|
||||
|
||||
// Set the slave address of the LP5024 driver
|
||||
RgbDriver::RgbDriver(char address)
|
||||
{
|
||||
slaveAddress = address;
|
||||
}
|
||||
|
||||
// Public Methods
|
||||
|
||||
// Set Chip_EN=0 to enter STANDBY mode
|
||||
int RgbDriver::selectStandbyMode() {
|
||||
return transmit(DEVICE_CONFIG0, 0x00);
|
||||
}
|
||||
|
||||
// Set Chip_EN=1 to enter normal mode
|
||||
int RgbDriver::selectNormalMode() {
|
||||
Wire.begin();
|
||||
return transmit(DEVICE_CONFIG0, 0x40);
|
||||
}
|
||||
|
||||
// Reset the LP5024
|
||||
int RgbDriver::reset() {
|
||||
int status = transmit(RESET, 0xFF);
|
||||
if (status == 0) {
|
||||
status = transmit(RESET, 0x00);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// Set the LP5024 configuration
|
||||
int RgbDriver::setDeviceConfig(bool Log_Scale_EN,
|
||||
bool Power_Save_EN,
|
||||
bool Auto_Incr_EN,
|
||||
bool PWM_Dithering_EN,
|
||||
bool Max_Current_Option,
|
||||
bool LED_Global_Off) {
|
||||
char config = Log_Scale_EN * 32 +
|
||||
Power_Save_EN * 16 +
|
||||
Auto_Incr_EN * 8 +
|
||||
PWM_Dithering_EN * 4 +
|
||||
Max_Current_Option * 2 +
|
||||
LED_Global_Off;
|
||||
return transmit(DEVICE_CONFIG1, config);
|
||||
}
|
||||
|
||||
// Enable or disable individual LEDs
|
||||
int RgbDriver::setLedConfig(bool LED7_Bank_EN,
|
||||
bool LED6_Bank_EN,
|
||||
bool LED5_Bank_EN,
|
||||
bool LED4_Bank_EN,
|
||||
bool LED3_Bank_EN,
|
||||
bool LED2_Bank_EN,
|
||||
bool LED1_Bank_EN,
|
||||
bool LED0_Bank_EN) {
|
||||
char config = LED7_Bank_EN * 128 +
|
||||
LED6_Bank_EN * 64 +
|
||||
LED5_Bank_EN * 32 +
|
||||
LED4_Bank_EN * 16 +
|
||||
LED3_Bank_EN * 8 +
|
||||
LED2_Bank_EN * 4 +
|
||||
LED1_Bank_EN * 2 +
|
||||
LED0_Bank_EN;
|
||||
return transmit(LED_CONFIG0, config);
|
||||
}
|
||||
|
||||
// Set the brightness for all LEDs
|
||||
int RgbDriver::setBankBrightness(char bank_brightness) {
|
||||
return transmit(BANK_BRIGHTNESS, bank_brightness);
|
||||
}
|
||||
|
||||
// Set the colour for all LEDs
|
||||
int RgbDriver::setBankColour(char red, char green, char blue) {
|
||||
// RED
|
||||
int status = transmit(BANK_A_COLOR, red);
|
||||
// GREEN
|
||||
if (status == 0) {
|
||||
transmit(BANK_B_COLOR, green);
|
||||
}
|
||||
// BLUE
|
||||
if (status == 0) {
|
||||
transmit(BANK_C_COLOR, blue);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// Set the brightness for an individual LED
|
||||
int RgbDriver::setLedBrightness(char led, char brightness) {
|
||||
char addr = led + 0x07;
|
||||
return transmit(addr, brightness);
|
||||
}
|
||||
|
||||
// Set the colour for an individual LED
|
||||
int RgbDriver::setLedColour(char led, char red, char green, char blue) {
|
||||
char redAddr = led * 3 + 0x0F;
|
||||
char greenAddr = led * 3 + 0x10;
|
||||
char blueAddr = led * 3 + 0x11;
|
||||
// RED
|
||||
int status = transmit(redAddr, red);
|
||||
// GREEN
|
||||
if (status == 0) {
|
||||
transmit(greenAddr, green);
|
||||
}
|
||||
// BLUE
|
||||
if (status == 0) {
|
||||
transmit(blueAddr, blue);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// Private Methods
|
||||
|
||||
// Transmit data to the LP5025 via I2C
|
||||
int RgbDriver::transmit(char addr, char data) {
|
||||
Wire.beginTransmission(slaveAddress);
|
||||
Wire.write(addr);
|
||||
Wire.write(data);
|
||||
return Wire.endTransmission();
|
||||
}
|
51
samd/src/main.cpp
Normal file
51
samd/src/main.cpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
#include <Arduino.h>
|
||||
#include "RgbDriver.h"
|
||||
|
||||
RgbDriver rgbDriver(0b0101000);
|
||||
|
||||
int mapLEDIndex(int idx) {
|
||||
switch(idx) {
|
||||
case 0: return 1;
|
||||
case 1: return 0;
|
||||
case 2: return 7;
|
||||
case 3: return 6;
|
||||
case 4: return 5;
|
||||
case 5: return 4;
|
||||
case 6: return 3;
|
||||
case 7: return 2;
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
int idx;
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
delay(5000);
|
||||
|
||||
Serial.println("Starting up!");
|
||||
rgbDriver.selectNormalMode();
|
||||
rgbDriver.setDeviceConfig(true, true, true, true, false, false);
|
||||
rgbDriver.setLedConfig(false, false, false, false, false, false, false, false);
|
||||
|
||||
Serial.println("Lighting LEDS");
|
||||
|
||||
for (int i = 0; i< 8; i++) {
|
||||
idx = mapLEDIndex(i);
|
||||
rgbDriver.setLedBrightness(idx, 0x0f);
|
||||
rgbDriver.setLedColour(idx, 0xff, 0x00, 0x99);
|
||||
delay(500);
|
||||
}
|
||||
Serial.println("LEDS Lit!");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
11
samd/test/README
Normal file
11
samd/test/README
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
This directory is intended for PlatformIO Test Runner and project tests.
|
||||
|
||||
Unit Testing is a software testing method by which individual units of
|
||||
source code, sets of one or more MCU program modules together with associated
|
||||
control data, usage procedures, and operating procedures, are tested to
|
||||
determine whether they are fit for use. Unit testing finds problems early
|
||||
in the development cycle.
|
||||
|
||||
More information about PlatformIO Unit Testing:
|
||||
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
Loading…
Reference in a new issue