Skip to content

Commit 40c4682

Browse files
committed
Separate data types in a stand-along header file for C compatibilities.
Changed data types from 'byte' 'word' to 'uint8_t' and 'uint16_t'. Changed member name in bc7215FormatPkt_t from 'byte' to 'inByte' to avoid Arduino key words.
1 parent e64b1aa commit 40c4682

File tree

4 files changed

+546
-151
lines changed

4 files changed

+546
-151
lines changed

library.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name=IR-infrared Remote Control Decoder-Simulator
2-
version=1.1.1
1+
name=BC7215 Universal IR Remote Control Decoder/Encoder Driver
2+
version=2.0.0
33
author=Bitcode
44
maintainer=Bitcode <[email protected]>
55
sentence=Driver for BC7215, an 8-pin universal IR remote control signal decoder/generator chip.
6-
paragraph=This library can be used to decode/simulate any IR remote controls, and also can be used for IR communication. It uses hardware or software serial port to interface with BC7215, and provides functions to operate BC7215. 4 examples are provided with the library: IR remote decoder, programmable remote control, IR controlled switch, and IR data communication.
6+
paragraph=BC7215 is able to decode/generate any IR remote control signal format, and also can be used for IR communication. It uses hardware or software serial port to interface with BC7215, and provides functions to operate BC7215. 4 examples are provided with the library: IR remote decoder, programmable remote control, IR controlled switch, and IR data communication.
77
category=Communication
88
url=https://github.com/bitcode-tech/bc7215
99
architectures=*

src/bc7215.cpp

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void BC7215::setShutDown()
5353
bc7215Status.cmdComplete = 0;
5454
}
5555

56-
void BC7215::setRxMode(byte mode)
56+
void BC7215::setRxMode(uint8_t mode)
5757
{
5858
if ((modPin == -1) || ((modPin >= 0) && (digitalRead(modPin) == HIGH))) // if MOD is HIGH
5959
{
@@ -74,7 +74,7 @@ void BC7215::clrData()
7474
bc7215Status.dataPktReady = 0;
7575
}
7676

77-
word BC7215::getLen()
77+
uint16_t BC7215::getLen()
7878
{
7979
statusUpdate();
8080
if (bc7215Status.dataPktReady)
@@ -87,7 +87,7 @@ word BC7215::getLen()
8787
}
8888
}
8989

90-
word BC7215::dpketSize()
90+
uint16_t BC7215::dpketSize()
9191
{
9292
statusUpdate();
9393
if (bc7215Status.dataPktReady)
@@ -100,15 +100,15 @@ word BC7215::dpketSize()
100100
}
101101
}
102102

103-
byte BC7215::getData(bc7215DataVarPkt_t* target)
103+
uint8_t BC7215::getData(bc7215DataVarPkt_t* target)
104104
{
105105
# if BC7215_BUFFER_SIZE > 255
106-
word i;
106+
uint16_t i;
107107
# else
108-
byte i;
108+
uint8_t i;
109109
# endif
110110
statusUpdate();
111-
byte status = 0xff;
111+
uint8_t status = 0xff;
112112
if (bc7215Status.dataPktReady)
113113
{
114114
status = bufBackRead(datEndPos, 2);
@@ -122,15 +122,15 @@ byte BC7215::getData(bc7215DataVarPkt_t* target)
122122
return status;
123123
}
124124

125-
byte BC7215::getData(bc7215DataMaxPkt_t& target)
125+
uint8_t BC7215::getData(bc7215DataMaxPkt_t& target)
126126
{
127127
return getData(reinterpret_cast<bc7215DataVarPkt_t*>(&target));
128128
}
129129

130130

131-
word BC7215::getRaw(void* addr, word size)
131+
uint16_t BC7215::getRaw(void* addr, uint16_t size)
132132
{
133-
word i;
133+
uint16_t i;
134134
statusUpdate();
135135
if (bc7215Status.dataPktReady)
136136
{
@@ -142,7 +142,7 @@ word BC7215::getRaw(void* addr, word size)
142142

143143
for (i = 0; i < size; i++)
144144
{
145-
*((byte*)addr + i) = bufRead(datStartPos, i);
145+
*((uint8_t*)addr + i) = bufRead(datStartPos, i);
146146
}
147147
}
148148
else
@@ -165,10 +165,10 @@ void BC7215::clrFormat()
165165
bc7215Status.formatPktReady = 0;
166166
}
167167

168-
byte BC7215::getFormat(bc7215FormatPkt_t& target)
168+
uint8_t BC7215::getFormat(bc7215FormatPkt_t& target)
169169
{
170-
byte i;
171-
byte signature;
170+
uint8_t i;
171+
uint8_t signature;
172172

173173
statusUpdate();
174174
signature = 0xff;
@@ -188,9 +188,9 @@ byte BC7215::getFormat(bc7215FormatPkt_t& target)
188188
# endif
189189

190190
#if BC7215_BUFFER_SIZE > 255
191-
byte BC7215::bufBackRead(word pos, word n)
191+
uint8_t BC7215::bufBackRead(uint16_t pos, uint16_t n)
192192
#else
193-
byte BC7215::bufBackRead(byte pos, byte n)
193+
uint8_t BC7215::bufBackRead(uint8_t pos, uint8_t n)
194194
#endif
195195
{
196196
if (pos >= n)
@@ -204,9 +204,9 @@ byte BC7215::getFormat(bc7215FormatPkt_t& target)
204204
}
205205

206206
#if BC7215_BUFFER_SIZE > 255
207-
byte BC7215::bufRead(word pos, word n)
207+
uint8_t BC7215::bufRead(uint16_t pos, uint16_t n)
208208
#else
209-
byte BC7215::bufRead(byte pos, byte n)
209+
uint8_t BC7215::bufRead(uint8_t pos, uint8_t n)
210210
#endif
211211
{
212212
if (pos + n >= BC7215_BUFFER_SIZE)
@@ -225,22 +225,22 @@ byte BC7215::getFormat(bc7215FormatPkt_t& target)
225225

226226
void BC7215::loadFormat(const bc7215FormatPkt_t& source)
227227
{
228-
byte i;
228+
uint8_t i;
229229
if ((modPin == -2) || ((modPin >= 0) && (digitalRead(modPin) == LOW))) // if MOD is LOW (bc7215 is in transmit mode)
230230
{
231231
sendOneByte(0xf6);
232232
sendOneByte(0x01);
233233
for (i = 0; i < sizeof(bc7215FormatPkt_t); i++)
234234
{
235-
byteStuffingSend(*(reinterpret_cast<const byte*>(&source) + i));
235+
byteStuffingSend(*(reinterpret_cast<const uint8_t*>(&source) + i));
236236
}
237237
}
238238
}
239239

240240
void BC7215::irTx(const bc7215DataVarPkt_t* source)
241241
{
242-
word i;
243-
word bytes;
242+
uint16_t i;
243+
uint16_t bytes;
244244
if ((modPin == -2) || ((modPin >= 0) && (digitalRead(modPin) == LOW))) // check if bc7215 is in trasmitting mode
245245
{
246246
if ((source->bitLen >= 8) && (source->bitLen < 0x1000))
@@ -251,7 +251,7 @@ void BC7215::irTx(const bc7215DataVarPkt_t* source)
251251
bytes = sizeof(source->bitLen) + (source->bitLen + 7) / 8; // set bytes = total number of data bytes +2
252252
for (i = 0; i < bytes; i++) // send from 2nd byte of the data packet
253253
{
254-
byteStuffingSend(*((byte*)source + i));
254+
byteStuffingSend(*((uint8_t*)source + i));
255255
}
256256
}
257257
}
@@ -262,9 +262,9 @@ void BC7215::irTx(const bc7215DataMaxPkt_t& source)
262262
irTx(reinterpret_cast<const bc7215DataVarPkt_t*>(&source));
263263
}
264264

265-
void BC7215::sendRaw(const void* source, word size)
265+
void BC7215::sendRaw(const void* source, uint16_t size)
266266
{
267-
word i;
267+
uint16_t i;
268268
if ((modPin == -2) || ((modPin >= 0) && (digitalRead(modPin) == LOW)))
269269
{
270270
if (size < 0x200)
@@ -276,7 +276,7 @@ void BC7215::sendRaw(const void* source, word size)
276276
byteStuffingSend((size * 8) >> 8);
277277
for (i = 0; i < size; i++)
278278
{
279-
byteStuffingSend(*((byte*)source + i));
279+
byteStuffingSend(*((uint8_t*)source + i));
280280
}
281281
}
282282
}
@@ -312,11 +312,11 @@ void BC7215::clrNOCA(bc7215FormatPkt_t& formatPkt)
312312
formatPkt.signature.bits.noCA = 0;
313313
}
314314

315-
byte BC7215::crc8(const void* data, word len)
315+
uint8_t BC7215::crc8(const void* data, uint16_t len)
316316
{
317-
word i;
318-
byte j;
319-
byte crc = 0;
317+
uint16_t i;
318+
uint8_t j;
319+
uint8_t crc = 0;
320320
for (i = 0; i < len; ++i)
321321
{
322322
crc ^= *(reinterpret_cast<const unsigned char*>(data) +i);
@@ -335,7 +335,7 @@ byte BC7215::crc8(const void* data, word len)
335335
return crc;
336336
}
337337

338-
word BC7215::calSize(const bc7215DataVarPkt_t* dataPkt)
338+
uint16_t BC7215::calSize(const bc7215DataVarPkt_t* dataPkt)
339339
{
340340
if (dataPkt->bitLen < 0x1000)
341341
{
@@ -347,28 +347,28 @@ word BC7215::calSize(const bc7215DataVarPkt_t* dataPkt)
347347
}
348348
}
349349

350-
word BC7215::calSize(const bc7215DataMaxPkt_t& dataPkt)
350+
uint16_t BC7215::calSize(const bc7215DataMaxPkt_t& dataPkt)
351351
{
352352
return calSize(reinterpret_cast<const bc7215DataVarPkt_t*>(&dataPkt));
353353
}
354354

355355

356356
void BC7215::copyDpkt(void* target, bc7215DataVarPkt_t* source)
357357
{
358-
word i, totalLen;
358+
uint16_t i, totalLen;
359359
totalLen = calSize(source);
360360
if ((void*)source > target) // if source is located behind target in memory, copy from front to end
361361
{
362362
for (i = 0; i < totalLen; i++)
363363
{
364-
*((byte*)target + i) = *((byte*)source + i);
364+
*((uint8_t*)target + i) = *((uint8_t*)source + i);
365365
}
366366
}
367367
else if ((void*)source < target) // if source is located before target in memory, copy from end to front
368368
{
369369
for (i = totalLen; i > 0; i--)
370370
{
371-
*((byte*)target + i - 1) = *((byte*)source + i - 1);
371+
*((uint8_t*)target + i - 1) = *((uint8_t*)source + i - 1);
372372
}
373373
}
374374
}
@@ -379,10 +379,10 @@ void BC7215::copyDpkt(void* target, bc7215DataMaxPkt_t& source)
379379
}
380380

381381

382-
bool BC7215::compareDpkt(byte sig, const bc7215DataVarPkt_t* pkt1, const bc7215DataVarPkt_t* pkt2)
382+
bool BC7215::compareDpkt(uint8_t sig, const bc7215DataVarPkt_t* pkt1, const bc7215DataVarPkt_t* pkt2)
383383
{
384-
byte i, bits, dat1, dat2;
385-
word i16, len;
384+
uint8_t i, bits, dat1, dat2;
385+
uint16_t i16, len;
386386

387387
if (pkt1->bitLen != pkt2->bitLen)
388388
{
@@ -433,13 +433,13 @@ bool BC7215::compareDpkt(byte sig, const bc7215DataVarPkt_t* pkt1, const bc7215D
433433
return 1;
434434
}
435435

436-
bool BC7215::compareDpkt(byte sig, const bc7215DataMaxPkt_t& pkt1, const bc7215DataMaxPkt_t& pkt2)
436+
bool BC7215::compareDpkt(uint8_t sig, const bc7215DataMaxPkt_t& pkt1, const bc7215DataMaxPkt_t& pkt2)
437437
{
438438
return BC7215::compareDpkt(sig, reinterpret_cast<const bc7215DataVarPkt_t*>(&pkt1), reinterpret_cast<const bc7215DataVarPkt_t*>(&pkt2));
439439
}
440440

441441

442-
void BC7215::byteStuffingSend(byte data)
442+
void BC7215::byteStuffingSend(uint8_t data)
443443
{
444444
if ((data == 0x7a) || (data == 0x7b))
445445
{
@@ -453,7 +453,7 @@ void BC7215::byteStuffingSend(byte data)
453453
}
454454

455455

456-
void BC7215::sendOneByte(byte data)
456+
void BC7215::sendOneByte(uint8_t data)
457457
{
458458
if (busyPin != -3) // if BUSY is connected to arduino
459459
{
@@ -471,12 +471,12 @@ void BC7215::statusUpdate()
471471
}
472472
}
473473

474-
void BC7215::processData(byte data)
474+
void BC7215::processData(uint8_t data)
475475
{
476476
#if ENABLE_RECEIVING == 1
477-
static byte previousData = 0;
478-
byte temp;
479-
word temp16;
477+
static uint8_t previousData = 0;
478+
uint8_t temp;
479+
uint16_t temp16;
480480
#endif
481481

482482
if ((modPin == -2) || ((modPin >= 0) && (digitalRead(modPin) == LOW))) // MOD=LOW means bc7215 is in transmit mode
@@ -506,7 +506,7 @@ void BC7215::processData(byte data)
506506
if ((byteCount + datCount <= BC7215_BUFFER_SIZE) && (!(bufBackRead(datEndPos, 2) & 0x80)))
507507
// if the format packet is not over writting the data packet and there is no error
508508
{
509-
bitLen = ((word)bufBackRead(datEndPos, 0) << 8) | bufBackRead(datEndPos, 1);
509+
bitLen = ((uint16_t)bufBackRead(datEndPos, 0) << 8) | bufBackRead(datEndPos, 1);
510510
bc7215Status.dataPktReady = 1;
511511
}
512512
}
@@ -515,7 +515,7 @@ void BC7215::processData(byte data)
515515
if (!(bufBackRead(lastWritingPos, 2) & 0x80))
516516
// if the buffer is not overflew and 'bit7' of the status byte the is not set (no error)
517517
{
518-
temp16 = ((word)bufBackRead(lastWritingPos, 0) << 8) | bufBackRead(lastWritingPos, 1);
518+
temp16 = ((uint16_t)bufBackRead(lastWritingPos, 0) << 8) | bufBackRead(lastWritingPos, 1);
519519
// get the bit count of the data packet
520520

521521
if ((temp16 + 7) / 8 + 3 == byteCount) // if the byte count of received packet is correct

0 commit comments

Comments
 (0)