Skip to content

Commit efbbca8

Browse files
committed
- added release note
- done v2.0.0 - added Millis, soft serial - I2C uses millis timer - master mkfile has show log
1 parent bde75c3 commit efbbca8

File tree

12 files changed

+234
-232
lines changed

12 files changed

+234
-232
lines changed

Makefile

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# This makefile doesn't build anything, just for maintaining the skeleton
2-
32
TOP = ./
4-
.PHONY: clean
53

4+
.PHONY: compile
65
# run all unit tests in all folders
76
check:
87
$(TOP)/project_manager.sh -k test/
@@ -26,6 +25,10 @@ clean:
2625
readme info:
2726
@view README.md
2827

28+
# show release note
29+
log:
30+
@view ReleaseNote.txt
31+
2932
# show help
3033
help:
31-
$(TOP)/project_manager.sh -h
34+
$(TOP)/project_manager.sh -h

ReleaseNote.txt

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@
44
** GPS NMEA data parser with LCD: track walked distance & position compared to initial one
55
** Simple calculator via serial port, supports +-*/() and non negative numbers
66

7-
* TODO v2.0.0 - matured C support & new mk files structure
8-
** INPROGRESS Software Serial C support upto baud 9600 for RX, 115200 for TX
7+
* DONE v2.0.0 - matured C support & new mk files structure
8+
- State "DONE" from "INPROGRESS" [2017-06-10 Sat 01:00]
9+
** DONE Software Serial C support upto 115200 for TX (RX isn't stable so it's dropped)
10+
- State "DONE" from "INPROGRESS" [2017-06-10 Sat 00:59]
911
** DONE Support Arduino IDE framework (Arduino Makefile)
1012
** DONE skeleton.mk is one-stop .mk for all projects, include it at the end of project's makefile
1113
** DONE create libutils.a
14+
** INPROGRESS v2.0.1 - migrate SerialDebugPrint api to non-macro, restructure i2c-console parser
15+
*** TODO change SerialDebugPrint* api & test src
16+
*** WAIT move i2c-console parser to module & callback management
17+
*** WAIT GPS breakout board to output to softserial
1218

1319
* WAIT v2.1.0 - Google test support & C sensor library support
1420
** add common/makefiles/gtest.mk
21+
*** add simple gtest project
1522
** motion sensor test code
1623
** hand clap sound detector
1724
** full range adc & pin change interrupt C support

common/utils/AVRString.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define UTILS_AVRSTRING_H_
1212

1313
#ifdef DEBUG
14-
#define STRING_MAXLEN 80 // max string length for all strings
14+
#define STRING_MAXLEN 128 // max string length for all strings
1515
#else
1616
#define STRING_MAXLEN 128 // max string length for all strings
1717
#endif

common/utils/I2C.c

+12-5
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ void i2c_init(uint8_t bdiv)
247247
TWSR = 0; // Set prescalar for 1
248248
TWBR = bdiv; // Set bit rate register
249249

250-
MillisInit();
250+
MillisInit(2);
251251
}
252252

253253
static volatile uint8_t _i2cIsRunning;
@@ -300,8 +300,14 @@ uint8_t I2CSendnRecvData(uint8_t address, const uint8_t * txdata,
300300
* 1 on NAK recv
301301
* 2 on START not ok
302302
* 3 on address not sent ok
303-
* 4 on unknown
303+
* 4 on timeout, check your wiring
304+
* 5 on unknown error
304305
*/
306+
#ifdef DEBUG
307+
#define _I2C_TIMEOUT_INTERVAL 1000
308+
#else
309+
#define _I2C_TIMEOUT_INTERVAL 100
310+
#endif
305311
uint8_t I2CCheckAlive(uint8_t address)
306312
{
307313
if (_i2cIsRunning)
@@ -310,7 +316,7 @@ uint8_t I2CCheckAlive(uint8_t address)
310316

311317
uint8_t status;
312318
uint8_t retVal = 0;
313-
unsigned long long initMillis = 0;
319+
unsigned long initMillis = 0;
314320
uint8_t isValid = 0;
315321

316322
// send I2C start
@@ -319,14 +325,15 @@ uint8_t I2CCheckAlive(uint8_t address)
319325

320326
initMillis = Millis();
321327
isValid = 0;
322-
while ( Millis() - initMillis < 100)
328+
while ( Millis() - initMillis < _I2C_TIMEOUT_INTERVAL)
323329
{
324330
if ((TWCR & (1 << TWINT))) // Wait for TWINT to be set in 100ms
325331
{
326332
isValid = 1;
327333
break;
328334
}
329335
}
336+
TRACE()
330337
if (!isValid)
331338
{
332339
retVal = 4;
@@ -349,7 +356,7 @@ uint8_t I2CCheckAlive(uint8_t address)
349356

350357
initMillis = Millis();
351358
isValid = 0;
352-
while ( Millis() - initMillis < 100)
359+
while ( Millis() - initMillis < _I2C_TIMEOUT_INTERVAL)
353360
{
354361
if ((TWCR & (1 << TWINT))) // Wait for TWINT to be set in 100ms
355362
{

common/utils/I2C.h

+17-1
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,33 @@
1111
#include <inttypes.h>
1212

1313
/**
14+
* call this before calling any below apis
1415
*
1516
*/
1617
void I2CInit(void);
1718

1819
/**
20+
* Send only data on i2c
1921
*
22+
* @param address - 7bit address
23+
* @param data
24+
* @param datalen
25+
* @param isSlowTX - slow sending between bytes
26+
* @return 0 on success
2027
*/
2128
uint8_t I2CSendData(uint8_t address, const uint8_t * data, uint8_t datalen, uint8_t isSlowTX);
2229

2330
/**
31+
* Send and then recv data on i2c
32+
*
2433
*
34+
* @param address - 7bit address
35+
* @param txdata
36+
* @param txdatalen
37+
* @param rxdata
38+
* @param rxdatalen
39+
* @param isSlowTX - slow sending between bytes
40+
* @return 0 on success
2541
*/
2642
uint8_t I2CSendnRecvData(uint8_t address, const uint8_t * txdata, uint8_t txdatalen,
2743
uint8_t * rxdata, uint8_t rxdatalen, uint8_t isSlowTX);
@@ -34,7 +50,7 @@ uint8_t I2CSendnRecvData(uint8_t address, const uint8_t * txdata, uint8_t txdata
3450
* 1 on NAK recv
3551
* 2 on START not ok
3652
* 3 on address not sent ok
37-
* 4 on timeout
53+
* 4 on timeout, check your wiring
3854
* 5 on unknown error
3955
*/
4056
uint8_t I2CCheckAlive(uint8_t address);

common/utils/Millis.c

+29-9
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
#include "Millis.h"
99
#include "Timer.h"
10+
#include "SerialDebug.h"
1011

1112
static Timer2Callback _mCallback_DB[MILLIS_MAX_CALLBACKS];
1213
static uint8_t _nCallback;
14+
static int _millisInit;
1315

14-
static volatile unsigned long long _mmillis;
16+
static volatile unsigned long _mmillis;
1517
static void incMillis()
1618
{
1719
++_mmillis;
@@ -26,33 +28,51 @@ static void incMillis()
2628
}
2729
}
2830

29-
30-
void MillisInit()
31+
char MillisInit(char timerNumber)
3132
{
3233
static char isInit = 0;
3334
if (isInit)
3435
{
35-
return;
36+
return _millisInit;
3637
}
3738
isInit = 1;
3839

3940
_mmillis = 0;
4041
_nCallback = 0;
42+
_millisInit = 0;
4143

42-
Timer2Init(1000);
43-
Timer2SetCallback(incMillis);
44+
if (timerNumber == 1)
45+
{
46+
Timer1Init(1);
47+
Timer1SetCallback(incMillis);
48+
}
49+
else if (timerNumber == 2)
50+
{
51+
Timer2Init(1000);
52+
Timer2SetCallback(incMillis);
53+
}
54+
else
55+
{
56+
_millisInit = 1;
57+
}
58+
59+
return _millisInit;
4460
}
4561

46-
unsigned long long Millis()
62+
unsigned long Millis()
4763
{
48-
MillisInit();
64+
if (MillisInit(2))
65+
{
66+
return 1;
67+
}
68+
4969
return _mmillis;
5070
}
5171

5272
uint8_t MillisRegisterCallback(Timer2Callback callback)
5373
{
5474
uint8_t retVal = 0;
55-
MillisInit();
75+
MillisInit(2);
5676

5777
if ( _nCallback == MILLIS_MAX_CALLBACKS)
5878
{

common/utils/Millis.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@
1313
#define MILLIS_MAX_CALLBACKS 3
1414

1515
/**
16-
* Init millisecond, this will use timer2, don't use timer2 if use this Millis
16+
* Init millisecond, this will use timer
17+
* If other apis called before this API, it will default to timer 2
1718
*
19+
* @param timerNumber - timer 1 or 2
1820
*/
19-
void MillisInit();
21+
char MillisInit(char timerNumber);
2022

2123
/**
22-
* main getter of millis
24+
* main getter of millis, will always return 1 if error on init
2325
*/
24-
unsigned long long Millis();
26+
unsigned long Millis();
2527

2628
/**
2729
* Register callback function for every millisecond

0 commit comments

Comments
 (0)