Skip to content

Commit b24bcbe

Browse files
authored
chore: silence UART on begin (#141)
* chore: Remove chatter from `begin` method (serial) * chore: remove old tests * updated 'src/note-c/' * git-subtree-dir: src/note-c * git-subtree-split: 022e83c8e54d72edf01502dc9b7bcd3be1d0d9c5
1 parent 4618c1b commit b24bcbe

File tree

11 files changed

+447
-551
lines changed

11 files changed

+447
-551
lines changed

src/Notecard.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@
4444

4545
#include "NoteTime.h"
4646

47-
// AUX serial throttling is based on the Arduino define `SERIAL_RX_BUFFER_SIZE`.
48-
// Unfortunately, some platforms do NOT specify the define. In this case, 64
49-
// bytes is selected as the default value, because it is a common buffer size
50-
// across several platforms.
51-
#ifndef SERIAL_RX_BUFFER_SIZE
52-
#define SERIAL_RX_BUFFER_SIZE 64
53-
#pragma message "\n\x1B[0;33mSERIAL_RX_BUFFER_SIZE has not been specified for this platform!\n\nThe value is used to set the default Notecard AUX Serial write speeds.\nA value (" NOTE_C_STRINGIZE(SERIAL_RX_BUFFER_SIZE) ") has been specified on your behalf. Use the 'card.aux.serial'\nrequest to tailor the AUX Serial speed to your board and/or application.\nhttps://dev.blues.io/api-reference/notecard-api/card-requests/#card-aux-serial\x1B[0;0m"
54-
#endif
55-
5647
/***************************************************************************
5748
SINGLETON ABSTRACTION (REQUIRED BY NOTE-C)
5849
***************************************************************************/
@@ -254,15 +245,6 @@ void Notecard::begin(NoteSerial * noteSerial_)
254245
if (noteSerial) {
255246
NoteSetFnSerial(noteSerialReset, noteSerialTransmit,
256247
noteSerialAvailable, noteSerialReceive);
257-
258-
// Set the default debug serial throttling
259-
J *req = NoteNewRequest("card.aux.serial");
260-
if (req != NULL)
261-
{
262-
JAddIntToObject(req, "max", SERIAL_RX_BUFFER_SIZE - 1);
263-
JAddIntToObject(req, "ms", 1);
264-
NoteRequestWithRetry(req, 15);
265-
}
266248
} else {
267249
NoteSetFnSerial(nullptr, nullptr, nullptr, nullptr);
268250
}

src/note-c/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ __pycache__/
1010
settings.json
1111

1212
# Development Artifacts
13+
CMakeFiles/
14+
CMakeCache.txt
1315
cppcheck_output.txt

src/note-c/Dockerfile

Lines changed: 0 additions & 97 deletions
This file was deleted.

src/note-c/n_helpers.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,31 @@ NOTE_C_STATIC int _yToDays(int year);
8080

8181
static const char NOTE_C_BINARY_EOP = '\n';
8282

83+
//**************************************************************************/
84+
/*!
85+
@brief Configure the flow control for the auxiliary serial port.
86+
@param bufSize The size of the receive buffer.
87+
@param delayMs The time to wait between reads.
88+
89+
@returns `true` on success, `false` on failure.
90+
*/
91+
/**************************************************************************/
92+
bool NoteAuxSerialFlowControl(int bufSize, int delayMs)
93+
{
94+
bool result = false;
95+
96+
J *req = NoteNewRequest("card.aux.serial");
97+
if (req != NULL) {
98+
JAddIntToObject(req, "max", bufSize - 1);
99+
JAddIntToObject(req, "ms", delayMs);
100+
result = NoteRequest(req);
101+
} else {
102+
NOTE_C_LOG_ERROR(ERRSTR("Failed to configure AUX serial flow control", c_mem));
103+
}
104+
105+
return result;
106+
}
107+
83108
//**************************************************************************/
84109
/*!
85110
@brief Decode binary data received from the Notecard.

src/note-c/n_hooks.c

Lines changed: 91 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -207,25 +207,25 @@ NOTE_C_STATIC void _noteSetActiveInterface(int interface)
207207
hookActiveInterface = interface;
208208

209209
switch (interface) {
210-
case NOTE_C_INTERFACE_SERIAL:
211-
notecardReset = _serialNoteReset;
212-
notecardTransaction = _serialNoteTransaction;
213-
notecardChunkedReceive = _serialChunkedReceive;
214-
notecardChunkedTransmit = _serialChunkedTransmit;
215-
break;
216-
case NOTE_C_INTERFACE_I2C:
217-
notecardReset = _i2cNoteReset;
218-
notecardTransaction = _i2cNoteTransaction;
219-
notecardChunkedReceive = _i2cNoteChunkedReceive;
220-
notecardChunkedTransmit = _i2cNoteChunkedTransmit;
221-
break;
222-
default:
223-
hookActiveInterface = NOTE_C_INTERFACE_NONE; // unrecognized interfaces are disabled
224-
notecardReset = NULL;
225-
notecardTransaction = NULL;
226-
notecardChunkedReceive = NULL;
227-
notecardChunkedTransmit = NULL;
228-
break;
210+
case NOTE_C_INTERFACE_SERIAL:
211+
notecardReset = _serialNoteReset;
212+
notecardTransaction = _serialNoteTransaction;
213+
notecardChunkedReceive = _serialChunkedReceive;
214+
notecardChunkedTransmit = _serialChunkedTransmit;
215+
break;
216+
case NOTE_C_INTERFACE_I2C:
217+
notecardReset = _i2cNoteReset;
218+
notecardTransaction = _i2cNoteTransaction;
219+
notecardChunkedReceive = _i2cNoteChunkedReceive;
220+
notecardChunkedTransmit = _i2cNoteChunkedTransmit;
221+
break;
222+
default:
223+
hookActiveInterface = NOTE_C_INTERFACE_NONE; // unrecognized interfaces are disabled
224+
notecardReset = NULL;
225+
notecardTransaction = NULL;
226+
notecardChunkedReceive = NULL;
227+
notecardChunkedTransmit = NULL;
228+
break;
229229
}
230230
}
231231

@@ -404,6 +404,38 @@ void NoteSetFnSerial(serialResetFn resetFn, serialTransmitFn transmitFn,
404404
_UnlockNote();
405405
}
406406

407+
/*!
408+
* @brief Set the default Serial hooks if they aren't already set
409+
* @param resetFn The platform-specific serial reset function.
410+
* @param transmitFn The platform-specific serial transmit function.
411+
* @param availFn The platform-specific serial available function.
412+
* @param receiveFn The platform-specific serial receive function.
413+
*/
414+
void NoteSetFnSerialDefault(serialResetFn resetFn, serialTransmitFn transmitFn,
415+
serialAvailableFn availFn, serialReceiveFn receiveFn)
416+
{
417+
_LockNote();
418+
419+
if (hookSerialReset == NULL) {
420+
hookSerialReset = resetFn;
421+
}
422+
if (hookSerialTransmit == NULL) {
423+
hookSerialTransmit = transmitFn;
424+
}
425+
if (hookSerialAvailable == NULL) {
426+
hookSerialAvailable = availFn;
427+
}
428+
if (hookSerialReceive == NULL) {
429+
hookSerialReceive = receiveFn;
430+
}
431+
432+
if (hookActiveInterface == NOTE_C_INTERFACE_NONE) {
433+
_noteSetActiveInterface(NOTE_C_INTERFACE_SERIAL);
434+
}
435+
436+
_UnlockNote();
437+
}
438+
407439
/*!
408440
@brief Set the platform-specific hooks for communicating with the Notecard over
409441
I2C, as well as the I2C address of the Notecard and maximum transmission
@@ -436,6 +468,46 @@ void NoteSetFnI2C(uint32_t notecardAddr, uint32_t maxTransmitSize,
436468
_UnlockNote();
437469
}
438470

471+
/*!
472+
* @brief Set the default I2C hooks if they aren't already set
473+
* @param notecardAddr The I2C address of the Notecard. Pass 0 to use the default
474+
* address.
475+
* @param maxTransmitSize The max number of bytes to send to the Notecard in a
476+
* single I2C segment. Pass 0 to use the default maximum transmission
477+
* size.
478+
* @param resetFn The platform-specific I2C reset function.
479+
* @param transmitFn The platform-specific I2C transmit function.
480+
* @param receiveFn The platform-specific I2C receive function.
481+
*/
482+
void NoteSetFnI2cDefault(uint32_t notecardAddr, uint32_t maxTransmitSize,
483+
i2cResetFn resetFn, i2cTransmitFn transmitFn,
484+
i2cReceiveFn receiveFn)
485+
{
486+
_LockNote();
487+
488+
if (i2cAddress == 0) {
489+
i2cAddress = notecardAddr;
490+
}
491+
if (i2cMax == 0) {
492+
i2cMax = maxTransmitSize;
493+
}
494+
if (hookI2CReset == NULL) {
495+
hookI2CReset = resetFn;
496+
}
497+
if (hookI2CTransmit == NULL) {
498+
hookI2CTransmit = transmitFn;
499+
}
500+
if (hookI2CReceive == NULL) {
501+
hookI2CReceive = receiveFn;
502+
}
503+
504+
if (hookActiveInterface == NOTE_C_INTERFACE_NONE) {
505+
_noteSetActiveInterface(NOTE_C_INTERFACE_I2C);
506+
}
507+
508+
_UnlockNote();
509+
}
510+
439511
//**************************************************************************/
440512
/*!
441513
@brief Set the platform-specific communications method to be disabled

src/note-c/n_i2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ bool _i2cNoteReset(void)
301301
break;
302302
}
303303

304-
NOTE_C_LOG_DEBUG("retrying I2C interface reset...")
304+
NOTE_C_LOG_DEBUG("retrying I2C interface reset...");
305305
}
306306

307307
// Done with the I2C bus

0 commit comments

Comments
 (0)