mirror of
https://github.com/OpenEPaperLink/OpenEPaperLink.git
synced 2026-03-21 07:06:36 +01:00
Led LUT for M3
This commit is contained in:
@@ -55,36 +55,92 @@ void watchdog_enable(int timeout) {
|
||||
}
|
||||
|
||||
uint32_t sleepMsEntry = 0;
|
||||
uint32_t ledinerv = 2500;
|
||||
uint32_t ledtime = 2000;
|
||||
bool ledred = false;
|
||||
bool ledgreen = false;
|
||||
bool ledblue = false;
|
||||
uint32_t loops = 0;
|
||||
bool interruped = false;
|
||||
|
||||
void setled(bool r,bool g,bool b){
|
||||
ledred = r;
|
||||
ledgreen = g;
|
||||
ledblue = b;
|
||||
ledinerv = 2500;
|
||||
ledtime = 2000;
|
||||
//uint8_t ledcfg[12] = {0b00100010,0x78,0b00100100,5,0x03,0b01000011,1,0xC2,0b1100001,10,10,0};
|
||||
//uint8_t ledcfg[12] = {0b00010010,0x7D,0,0,0x03,0xE8,0,0,0,0,0,0};
|
||||
uint8_t ledcfg[12] = {255,0,0,0,0,0,0,0,0,0,0,0};
|
||||
|
||||
void setled(uint64_t parta,u_int32_t partb){
|
||||
ledcfg[0] = parta & 0xFF;
|
||||
ledcfg[1] = (parta >> 8)& 0xFF;
|
||||
ledcfg[2] = (parta >> 16)& 0xFF;
|
||||
ledcfg[3] = (parta >> 24)& 0xFF;
|
||||
ledcfg[4] = (parta >> 32)& 0xFF;
|
||||
ledcfg[5] = (parta >> 40)& 0xFF;
|
||||
ledcfg[6] = (parta >> 48)& 0xFF;
|
||||
ledcfg[7] = (parta >> 56)& 0xFF;
|
||||
ledcfg[8] = partb & 0xFF;
|
||||
ledcfg[9] = (partb >> 8)& 0xFF;
|
||||
ledcfg[10] = (partb >> 16)& 0xFF;
|
||||
ledcfg[11] = (partb >> 24)& 0xFF;
|
||||
}
|
||||
|
||||
void resettimer(){
|
||||
sleepMsEntry = sleepMsEntry + 999999999;
|
||||
//tell the sleep function to net sleep again
|
||||
sleepMsEntry = sleepMsEntry - 999999999;
|
||||
loops = 0;
|
||||
interruped = true;
|
||||
}
|
||||
|
||||
void sleepForMs(uint32_t ms) {
|
||||
// Turn everything off for minimal deep sleep current
|
||||
radioRxEnable(0);
|
||||
NRF_CLOCK->TASKS_HFCLKSTOP = 1U;
|
||||
while ((NRF_CLOCK->HFCLKSTAT & 0x10001) == 0x10001)
|
||||
;
|
||||
Serial.end();
|
||||
yield();
|
||||
//led and sleep stuff
|
||||
if(!ledred && !ledgreen && !ledblue)ledinerv = 99999999;
|
||||
void flashled(uint8_t color,uint8_t brightnes){
|
||||
uint8_t colorred = (color >> 5) & 0b00000111;
|
||||
uint8_t colorgreen = (color >> 2) & 0b00000111;
|
||||
uint8_t colorblue = color & 0b00000011;
|
||||
for(uint16_t i = 0;i < brightnes;i++){
|
||||
digitalWrite(LED_RED, !(colorred >= 7));
|
||||
digitalWrite(LED_GREEN, !(colorgreen >= 7));
|
||||
digitalWrite(LED_BLUE, !(colorblue >= 3));
|
||||
nrf_delay_us(100);
|
||||
digitalWrite(LED_RED, !(colorred >= 1));
|
||||
digitalWrite(LED_GREEN, !(colorgreen >= 1));
|
||||
nrf_delay_us(100);
|
||||
digitalWrite(LED_RED, !(colorred >= 6));
|
||||
digitalWrite(LED_GREEN, !(colorgreen >= 6));
|
||||
digitalWrite(LED_BLUE, !(colorblue >= 1));
|
||||
nrf_delay_us(100);
|
||||
digitalWrite(LED_RED, !(colorred >= 2));
|
||||
digitalWrite(LED_GREEN, !(colorgreen >= 2));
|
||||
nrf_delay_us(100);
|
||||
digitalWrite(LED_RED, !(colorred >= 5));
|
||||
digitalWrite(LED_GREEN, !(colorgreen >= 5));
|
||||
nrf_delay_us(100);
|
||||
digitalWrite(LED_RED, !(colorred >= 3));
|
||||
digitalWrite(LED_GREEN, !(colorgreen >= 3));
|
||||
digitalWrite(LED_BLUE, !(colorblue >= 2));
|
||||
nrf_delay_us(100);
|
||||
digitalWrite(LED_RED, !(colorred >= 4));
|
||||
digitalWrite(LED_GREEN, !(colorgreen >= 4));
|
||||
nrf_delay_us(100);
|
||||
digitalWrite(LED_RED, HIGH);
|
||||
digitalWrite(LED_GREEN, HIGH);
|
||||
digitalWrite(LED_BLUE, HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
void sleepwithinterrupts(uint32_t sleepinterval){
|
||||
yield();
|
||||
sleepMsEntry = millis();
|
||||
//sometimes we wake up early
|
||||
while (millis() - sleepMsEntry < sleepinterval){
|
||||
initRTC0(sleepinterval);
|
||||
__WFE();
|
||||
__SEV();
|
||||
__WFE();
|
||||
}
|
||||
}
|
||||
|
||||
void ledflashlogic(uint32_t ms){
|
||||
watchdog_enable(ms + 1000);
|
||||
uint8_t brightnes = ledcfg[0] >> 4 & 0b00001111;
|
||||
uint8_t mode = ledcfg[0] & 0b00001111;
|
||||
//lets not blink for short delays
|
||||
if(ms < 2000)mode = 15;
|
||||
//if(mode == 0)sleepwithinterrupts(ms);
|
||||
if(mode == 1){
|
||||
uint8_t color = ledcfg[1];
|
||||
uint32_t ledinerv = (ledcfg[2] << 24 )+ (ledcfg[3] << 16)+ (ledcfg[4] << 8)+ ledcfg[5];
|
||||
uint32_t sleepinterval = ledinerv;
|
||||
loops = ms / ledinerv;
|
||||
if(loops == 0){
|
||||
@@ -93,22 +149,81 @@ void sleepForMs(uint32_t ms) {
|
||||
}
|
||||
if(sleepinterval > ms)sleepinterval = ms;
|
||||
for(uint32_t i = 0;i < loops;i++){
|
||||
digitalWrite(LED_RED, !ledred);
|
||||
digitalWrite(LED_GREEN, !ledgreen);
|
||||
digitalWrite(LED_BLUE, !ledblue);
|
||||
nrf_delay_us(ledtime);
|
||||
digitalWrite(LED_RED, HIGH);
|
||||
digitalWrite(LED_GREEN, HIGH);
|
||||
digitalWrite(LED_BLUE, HIGH);
|
||||
initRTC0(sleepinterval);
|
||||
sleepMsEntry = millis();
|
||||
while (millis() - sleepMsEntry < sleepinterval){
|
||||
__WFE();
|
||||
__SEV();
|
||||
__WFE();
|
||||
flashled(color,brightnes);
|
||||
sleepwithinterrupts(sleepinterval);
|
||||
}
|
||||
}
|
||||
else if(mode == 0){
|
||||
interruped = false;
|
||||
uint8_t interloopdelayfactor = 100;
|
||||
u_int8_t loopdelayfactor = 100;
|
||||
uint8_t c1 = ledcfg[1];
|
||||
uint8_t c2 = ledcfg[3];
|
||||
uint8_t c3 = ledcfg[5];
|
||||
uint8_t loop1delay = (ledcfg[2] >> 4) & 0b00001111;
|
||||
uint8_t loop2delay = (ledcfg[4] >> 4) & 0b00001111;
|
||||
uint8_t loop3delay = (ledcfg[6] >> 4) & 0b00001111;
|
||||
uint8_t loopcnt1 = ledcfg[2] & 0b00001111;
|
||||
uint8_t loopcnt2 = ledcfg[4] & 0b00001111;
|
||||
uint8_t loopcnt3 = ledcfg[6] & 0b00001111;
|
||||
uint8_t ildelay1 = 0;
|
||||
uint8_t ildelay2 = 0;
|
||||
uint8_t ildelay3 = 0;
|
||||
uint8_t grouprepeats = ledcfg[7];
|
||||
uint32_t fulllooptime1 = loopcnt1 * loop1delay * loopdelayfactor + ildelay1 * interloopdelayfactor;
|
||||
uint32_t fulllooptime2 = loopcnt2 * loop2delay * loopdelayfactor + ildelay2 * interloopdelayfactor;
|
||||
uint32_t fulllooptime3 = loopcnt3 * loop3delay * loopdelayfactor + ildelay3 * interloopdelayfactor;
|
||||
uint32_t looptimesum = fulllooptime1 + fulllooptime2 + fulllooptime3;
|
||||
int fittingrepeats = (int) ms / looptimesum;
|
||||
|
||||
grouprepeats = fittingrepeats;
|
||||
if(grouprepeats == 0)grouprepeats = 1;
|
||||
|
||||
for(int j = 0;j < grouprepeats;j++){
|
||||
|
||||
if(!interruped){
|
||||
for(int i = 0;i < loopcnt1;i++){
|
||||
flashled(c1,brightnes);
|
||||
sleepwithinterrupts(loop1delay * loopdelayfactor);
|
||||
if(interruped)break;
|
||||
}
|
||||
sleepwithinterrupts(ildelay1 * interloopdelayfactor);
|
||||
}
|
||||
if(!interruped){
|
||||
for(int i = 0;i < loopcnt2;i++){
|
||||
flashled(c2,brightnes);
|
||||
sleepwithinterrupts(loop2delay * loopdelayfactor);
|
||||
if(interruped)break;
|
||||
}
|
||||
sleepwithinterrupts(ildelay2 * interloopdelayfactor);
|
||||
}
|
||||
|
||||
if(!interruped){
|
||||
for(int i = 0;i < loopcnt3;i++){
|
||||
flashled(c3,brightnes);
|
||||
sleepwithinterrupts(loop3delay * loopdelayfactor);
|
||||
if(interruped)break;
|
||||
}
|
||||
sleepwithinterrupts(ildelay3 * interloopdelayfactor);
|
||||
}
|
||||
if(interruped)break;
|
||||
}
|
||||
}
|
||||
else sleepwithinterrupts(ms);
|
||||
}
|
||||
|
||||
void sleepForMs(uint32_t ms) {
|
||||
// Turn everything off for minimal deep sleep current
|
||||
radioRxEnable(0);
|
||||
NRF_CLOCK->TASKS_HFCLKSTOP = 1U;
|
||||
while ((NRF_CLOCK->HFCLKSTAT & 0x10001) == 0x10001);
|
||||
Serial.end();
|
||||
yield();
|
||||
//led and sleep stuff
|
||||
ledflashlogic(ms);
|
||||
//we have to restart the serial
|
||||
Serial.begin(115200);
|
||||
Serial.println("wu");
|
||||
}
|
||||
|
||||
#define LF_FREQUENCY 32768UL
|
||||
|
||||
@@ -52,5 +52,5 @@ int8_t startHFCLK(void);
|
||||
uint8_t isHFCLKstable(void);
|
||||
void boardGetOwnMac(uint8_t *mac);
|
||||
void sleepForMs(uint32_t ms);
|
||||
void setled(bool r,bool g,bool b);
|
||||
void setled(uint64_t parta,u_int32_t partb);
|
||||
void resettimer();
|
||||
@@ -7,7 +7,9 @@ board = nrf52811_dk
|
||||
framework = arduino
|
||||
debug_tool = stlink
|
||||
upload_protocol = stlink
|
||||
|
||||
lib_deps =
|
||||
stevemarple/SoftWire @ ^2.0.9
|
||||
stevemarple/AsyncDelay @ ^1.1.2
|
||||
|
||||
[env:Newton_M3_29_BWR]
|
||||
build_flags =
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <SoftWire.h>
|
||||
#include <AsyncDelay.h>
|
||||
|
||||
#include "comms.h"
|
||||
#include "drawing.h"
|
||||
@@ -12,6 +14,8 @@
|
||||
#include "userinterface.h"
|
||||
#include "wdt.h"
|
||||
|
||||
SoftWire sw(NFC_I2C_SDA, NFC_I2C_SCL);
|
||||
|
||||
extern "C" int _write(int file, char *ptr, int len) {
|
||||
(void)file; /* Not used, avoid warning */
|
||||
Serial.write(ptr, len);
|
||||
@@ -111,7 +115,48 @@ void setup() {
|
||||
|
||||
printf("BOOTED> %d.%d.%d%s\n", fwVersion / 100, (fwVersion % 100) / 10, (fwVersion % 10), fwVersionSuffix);
|
||||
|
||||
/*
|
||||
powerUp(INIT_I2C);
|
||||
pinMode(NFC_POWER, OUTPUT);
|
||||
digitalWrite(NFC_POWER,HIGH);
|
||||
|
||||
sw.setTimeout_ms(40);
|
||||
sw.begin();
|
||||
delay(50);
|
||||
|
||||
const uint8_t firstAddr = 1;
|
||||
const uint8_t lastAddr = 0x7F;
|
||||
Serial.println();
|
||||
Serial.print("I2C scan in range 0x");
|
||||
Serial.print(firstAddr, HEX);
|
||||
Serial.print(" - 0x");
|
||||
Serial.print(lastAddr, HEX);
|
||||
Serial.println(" (inclusive) ...");
|
||||
for (uint8_t addr = firstAddr; addr <= lastAddr; addr++) {
|
||||
delayMicroseconds(50);
|
||||
uint8_t startResult = sw.llStart((addr << 1) + 1); // Signal a read
|
||||
sw.stop();
|
||||
if (startResult == 0) {
|
||||
Serial.print("\rDevice found at 0x");
|
||||
Serial.println(addr, HEX);
|
||||
Serial.flush();
|
||||
}
|
||||
delay(50);
|
||||
}
|
||||
Serial.println("Finished");
|
||||
|
||||
Serial.println((uint8_t)0x55 << 1);
|
||||
|
||||
sw.beginTransmission(30);
|
||||
sw.write(uint8_t(0)); // Access the first register
|
||||
sw.endTransmission();
|
||||
|
||||
digitalWrite(NFC_POWER,LOW);
|
||||
pinMode(NFC_POWER, INPUT_PULLDOWN);
|
||||
|
||||
powerDown(INIT_I2C);
|
||||
|
||||
*/
|
||||
|
||||
//we always have NFC + NFC wake
|
||||
capabilities |= CAPABILITY_HAS_NFC;
|
||||
|
||||
@@ -117,20 +117,11 @@ static void configI2C(const bool setup) {
|
||||
if (setup == i2cActive)
|
||||
return;
|
||||
if (setup) {
|
||||
/*P1DIR &= ~(1 << 6);
|
||||
P1_6 = 1;
|
||||
P1FUNC |= (1 << 4) | (1 << 5);
|
||||
P1PULL |= (1 << 4) | (1 << 5);
|
||||
i2cInit();
|
||||
i2cCheckDevice(0x50); */
|
||||
// first transaction after init fails, this makes sure everything is ready for the first transaction
|
||||
pinMode(NFC_I2C_SCL,OUTPUT);
|
||||
pinMode(NFC_I2C_SDA,OUTPUT);
|
||||
} else {
|
||||
/*P1DIR |= (1 << 6);
|
||||
P1_6 = 0;
|
||||
P1FUNC &= ~((1 << 4) | (1 << 5));
|
||||
P1PULL &= ~((1 << 4) | (1 << 5));
|
||||
CLKEN &= ~0x10;
|
||||
IEN1 &= ~4;*/
|
||||
pinMode(NFC_I2C_SDA,INPUT);
|
||||
pinMode(NFC_I2C_SCL,INPUT);
|
||||
}
|
||||
i2cActive = setup;
|
||||
}
|
||||
|
||||
@@ -823,17 +823,11 @@ bool processAvailDataInfo(struct AvailDataInfo *avail) {
|
||||
}
|
||||
case DATATYPE_COMMAND_DATA:
|
||||
printf("CMD received\n");
|
||||
|
||||
//led cmd handeling
|
||||
if(avail->dataTypeArgument == CMD_LED_OFF)setled(false,false,false);
|
||||
if(avail->dataTypeArgument == CMD_LED_RED)setled(true,false,false);
|
||||
if(avail->dataTypeArgument == CMD_LED_GREEN)setled(false,true,false);
|
||||
if(avail->dataTypeArgument == CMD_LED_BLUE)setled(false,false,true);
|
||||
if(avail->dataTypeArgument == CMD_LED_YELLOW)setled(true,true,false);
|
||||
if(avail->dataTypeArgument == CMD_LED_CYAN)setled(false,true,true);
|
||||
if(avail->dataTypeArgument == CMD_LED_MAGENTA)setled(true,false,true);
|
||||
if(avail->dataTypeArgument == CMD_LED_WHITE)setled(true,true,true);
|
||||
|
||||
if(avail->dataTypeArgument == 4){
|
||||
Serial.println("LED CMD");
|
||||
setled(avail->dataVer,avail->dataSize);
|
||||
}
|
||||
powerUp(INIT_RADIO);
|
||||
sendXferComplete();
|
||||
powerDown(INIT_RADIO);
|
||||
|
||||
Reference in New Issue
Block a user