8000 added asr_NeoPixel.c · neurodavid/CubeCell-Arduino@1d262a6 · GitHub
[go: up one dir, main page]

8000 Skip to content

Commit 1d262a6

Browse files
added asr_NeoPixel.c
1 parent 538fac1 commit 1d262a6

File tree

4 files changed

+82
-10
lines changed

4 files changed

+82
-10
lines changed

cores/asr650x/asr_NeoPixel.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include <stdbool.h>
2+
#include <stdint.h>
3+
#include <stdlib.h>
4+
#include <string.h>
5+
#include <ASR_Arduino.h>
6+
#include <CyLib.h>
7+
8+
9+
10+
#define CYCLES_800_T0H 19 // 0.4us
11+
#define CYCLES_800_T1H 38// 0.8us
12+
#define CYCLES_800 60 // 1.25us per bit
13+
#define CYCLES_400_T0H 24// 0.5uS
14+
#define CYCLES_400_T1H 30// 1.2us
15+
#define CYCLES_400 75 // 2.5us per bit
16+
17+
void ASR_NeoPixelShow(
18+
uint8_t pin, uint8_t *pixels, uint32_t numBytes, bool is800KHz) {
19+
20+
uint8_t *p, *end, pix, mask;
21+
uint32_t t, time0, time1, period, startTime, pinMask,saveLoad,pinHigh,pinLow;
22+
23+
uint8 port=pin / PIN_NUMBER_IN_PORT;
24+
uint8 PIN_SHIFT=pin % PIN_NUMBER_IN_PORT;
25+
uint32 REG_DR=CYREG_GPIO_PRT0_DR + port * PORT_REG_SHFIT;
26+
uint8 Pin_MASK=0x01<<PIN_SHIFT;
27+
uint8 drVal = (uint8)((* (reg32 *) REG_DR) & (~Pin_MASK));
28+
29+
pinHigh=drVal|Pin_MASK;
30+
pinLow=drVal & (~(uint32_t)Pin_MASK);
31+
32+
p = pixels;
33+
end = p + numBytes;
34+
pix = *p++;
35+
mask = 0x80;
36+
startTime = 0;
37+
38+
period = CYCLES_800;
39+
time0 = period - CYCLES_800_T0H;
40+
time1 = period - CYCLES_800_T1H;
41+
42+
saveLoad = CY_SYS_SYST_RVR_REG;
43+
CY_SYS_SYST_RVR_REG = period;
44+
CY_SYS_SYST_CVR_REG = 0u;
45+
//pinMode(pin,OUTPUT);
46+
47+
for(t=time0;;t=time0) {
48+
while(CY_SYS_SYST_CVR_REG < period);//wait for bit start
49+
(* (reg32 *) REG_DR)=pinHigh; //write high
50+
if(pix & mask) t = time1;
51+
52+
while(CY_SYS_SYST_CVR_REG > t); // Wait high duration
53+
(* (reg32 *) REG_DR)=pinLow;//write low
54+
55+
if(!(mask >>= 1)) { // Next bit/byte
56+
if(p >= end) break;
57+
pix = *p++;
58+
mask = 0x80;
59+
}
60+
}
61+
while(CY_SYS_SYST_CVR_REG < period); //wait for the last bit.
62+
// (* (reg32 *) REG_DR)=pinLow;
63+
CY_SYS_SYST_RVR_REG = saveLoad;
64+
65+
}
66+
67+
68+
69+

cores/asr6601/lora/system/timer.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ void TimerIrqHandler( void )
290290
n++;
291291
cur = TimerListHead;
292292
TimerListHead = TimerListHead->Next;
293-
cur->IsRunning = false;
294293
exec_cb( cur->Callback );
295294
//update timestamps after callbacks
296295
TimeStampsUpdate();

cores/asr6601/peripheral/HardwareSerial.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ bool HardwareSerial::begin(uint32_t baud, uint32_t config, int rxPin, int txPin,
4040
_txPin = txPin;
4141

4242
_uart = uartStart(baud,config,_rxPin,_txPin);
43+
_uartSymbolTime=1000000/_baud*11;
44+
4345
if(_uart<0)
4446
return false;
4547
else
@@ -50,6 +52,7 @@ void HardwareSerial::updateBaudRate(unsigned long baud)
5052
{
5153
_baud = baud;
5254
uartStart(baud,_config,_rxPin,_txPin);
55+
_uartSymbolTime=1000000/_baud*11;
5356
}
5457

5558
void HardwareSerial::end()
@@ -119,6 +122,11 @@ size_t HardwareSerial::write(const uint8_t *buffer, size_t size)
119122
#endif
120123
}
121124

125+
void HardwareSerial::delayByte(void)
126+
{
127+
delayMicroseconds(11000000/_baud);
128+
}
129+
122130
uint32_t HardwareSerial::baudRate()
123131
{
124132
return _baud;
@@ -140,18 +148,12 @@ int HardwareSerial::read(uint8_t* buff, uint32_t timeout)
140148
}
141149
}
142150
int serialBuffer_index=0;
151+
int i=0;
143152
while(available())
144153
{
145154
buff[serialBuffer_index++]=read();
146-
147-
int i = 0;
148-
while(i<1000)
149-
{
150-
if(available())
151-
break;
152-
delayMicroseconds(1);
153-
i++;
154-
}
155+
if(available() == 0)
156+
delayByte();//wait for a byte
155157
}
156158
return serialBuffer_index;
157159
//Serial.write(serialBuffer,serialBuffer_index);

cores/asr6601/peripheral/HardwareSerial.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class HardwareSerial: public Print
2121
int read(uint8_t* buff, uint32_t timeout);
2222
void flush(void);
2323
void flush( bool txOnly);
24+
void delayByte();
2425
size_t write(uint8_t c);
2526
size_t write(const uint8_t *buffer, size_t size);
2627
bool busy(void);
@@ -55,6 +56,7 @@ class HardwareSerial: public Print
5556
int _rxPin=-1;
5657
int _txPin=-1;
5758
uint32_t _config;
59+
uint32_t _uartSymbolTime;
5860
};
5961

6062
extern HardwareSerial Serial;

0 commit comments

Comments
 (0)
0