-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gustavo Casanova
committed
May 8, 2020
1 parent
1978445
commit e0f8a87
Showing
40 changed files
with
553 additions
and
408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# v1.3 | ||
# v1.4 | ||
# Prerequisites | ||
*.d | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
# Test Apps v1.4 # | ||
# Test Apps v1.4 | ||
|
||
This folder contains simple apps that can be used to test the bootloader functionality. | ||
|
||
Choose any of then and compile it. The resulting ".hex" file has to be converted into a byte-array by using "timonel-hexparser". After that, the "payload.h" file obtained has to be included in the "/data/payloads" folder of "timonel-twim-ss" or "timonel-twim-ss" to be able to flash it into the T85. | ||
Choose any of then and compile it. The resulting ".hex" file has to be converted into a byte-array by using "[timonel-hexparser](/timonel-hexparser)". After that, the "payload.h" file obtained has to be included in the "/data/payloads" folder of "[timonel-twim-ss](/timonel-twim-ss/data/payloads)" or "[timonel-twim-ms](/timonel-twim-ms/data/payloads)" to be able to flash it into the T85. | ||
|
||
* avr-blink-twis: Simple led blink demo with I2C controllable through a serial console. | ||
|
||
* avr-native-blink: Simple AVR blink. | ||
|
||
* bare-t85-blink-io: Simple blink compiled with platformio. | ||
* bare-t85-blink-io: Simple blink compiled with platformio. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "nb-twi-cmd", | ||
"keywords": "nb-twi-cmd, i2c, twi, communications, arduino", | ||
"description": "NB TWI command set. Defines the comm protocol over TWI (I2C).", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/casanovg/timonel.git" | ||
}, | ||
"include": "nb-libs/cmd", | ||
"version": "0.5.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,19 +4,15 @@ | |
* ........................................... | ||
* File: NbMicro.cpp (Library) | ||
* ........................................... | ||
* Version: 1.4 / 2019-08-09 | ||
* Version: 0.9.0 / 2020-04-29 | ||
* [email protected] | ||
* ........................................... | ||
* This TWI (I2C) master library handles the communication protocol | ||
* with slave devices that implement the NB command set over a TWI | ||
* bus. In addition, the TwiBus class has methods to scan the bus in | ||
* search of the existing slave devices addresses. For single-slave | ||
* setups or those where all addresses are known in advance, this | ||
* last one could be dropped to save memory. | ||
* bus. | ||
*/ | ||
|
||
#include "NbMicro.h" | ||
#include "TimonelTwiM.h" | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
//////////// NBMICRO CLASS //////////// | ||
|
@@ -123,8 +119,10 @@ byte NbMicro::TwiCmdXmit(byte twi_cmd_arr[], byte cmd_size, byte twi_reply, byte | |
} | ||
// TWI command reply (one byte expected) | ||
if (reply_size == 0) { | ||
Wire.requestFrom(addr_, ++reply_size, STOP_ON_REQ); /* True: releases the bus with a stop after a master request. */ | ||
byte reply = Wire.read(); /* False: sends a restart, not releasing the bus. */ | ||
reply_size++; | ||
//Wire.requestFrom(addr_, ++reply_size, STOP_ON_REQ); /* True: releases the bus with a stop after a master request. */ | ||
Wire.requestFrom(addr_, ++reply_size); /* True: releases the bus with a stop after a master request. */ | ||
byte reply = Wire.read(); /* False: sends a restart, not releasing the bus. */ | ||
if (reply == twi_reply) { | ||
#if ((defined DEBUG_LEVEL) && (DEBUG_LEVEL >= 2)) | ||
USE_SERIAL.printf_P("[%s] > Command 0x%02X parsed OK <<< 0x%02X (single byte reply)\n\r", __func__, twi_cmd_arr[0], reply); | ||
|
@@ -139,8 +137,9 @@ byte NbMicro::TwiCmdXmit(byte twi_cmd_arr[], byte cmd_size, byte twi_reply, byte | |
} | ||
// TWI command reply (multiple bytes expected) | ||
else { | ||
byte reply_length = Wire.requestFrom(addr_, reply_size, STOP_ON_REQ); /* True: releases the bus with a stop after a master request. */ | ||
for (int i = 0; i < reply_size; i++) { /* False: sends a restart, not releasing the bus. */ | ||
//byte reply_length = Wire.requestFrom(addr_, reply_size, STOP_ON_REQ); /* True: releases the bus with a stop after a master request. */ | ||
byte reply_length = Wire.requestFrom(addr_, reply_size); /* True: releases the bus with a stop after a master request. */ | ||
for (int i = 0; i < reply_size; i++) { /* False: sends a restart, not releasing the bus. */ | ||
twi_reply_arr[i] = Wire.read(); | ||
} | ||
if ((twi_reply_arr[0] == twi_reply) && (reply_length == reply_size)) { | ||
|
@@ -176,116 +175,3 @@ byte NbMicro::InitMicro(void) { | |
#endif /* DEBUG_LEVEL */ | ||
return (TwiCmdXmit(INITSOFT, ACKINITS)); | ||
} | ||
|
||
#if ((defined MULTI_DEVICE) && (MULTI_DEVICE == true)) | ||
#pragma GCC warning "TwiBus device discovery functions code included in TWI master!" | ||
///////////////////////////////////////////////////////////////////////////// | ||
//////////// TWIBUS CLASS //////////// | ||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
// Class constructor | ||
TwiBus::TwiBus(byte sda, byte scl) : sda_(sda), scl_(scl) { | ||
if (!((sda == 0) && (scl == 0))) { | ||
#if ((defined DEBUG_LEVEL) && (DEBUG_LEVEL >= 1)) | ||
USE_SERIAL.printf_P("[%s] Creating a new I2C connection\n\r", __func__); | ||
#endif /* DEBUG_LEVEL */ | ||
Wire.begin(sda, scl); /* Init I2C sda:GPIO0, scl:GPIO2 (ESP-01) / sda:D3, scl:D4 (NodeMCU) */ | ||
reusing_twi_connection_ = false; | ||
} else { | ||
#if ((defined DEBUG_LEVEL) && (DEBUG_LEVEL >= 1)) | ||
USE_SERIAL.printf_P("[%s] Reusing I2C connection\n\r", __func__); | ||
#endif /* DEBUG_LEVEL */ | ||
reusing_twi_connection_ = true; | ||
} | ||
} | ||
|
||
// Class destructor | ||
TwiBus::~TwiBus() { | ||
// Destructor | ||
} | ||
|
||
/* _________________________ | ||
| | | ||
| ScanBus A | | ||
|_________________________| | ||
*/ | ||
// ScanBus (Overload A: Return the address and mode of the first TWI device found on the bus) | ||
byte TwiBus::ScanBus(bool *p_app_mode) { | ||
// Address 08 to 35: Timonel bootloader (app mode = false) | ||
// Address 36 to 63: Application firmware (app mode = true) | ||
#if ((defined DEBUG_LEVEL) && (DEBUG_LEVEL >= 1)) | ||
USE_SERIAL.printf_P("\n\r[%s] Scanning TWI bus, looking for the first device (lowest address) ...\n\r", __func__); | ||
#endif /* DEBUG_LEVEL */ | ||
byte twi_addr = LOW_TWI_ADDR; | ||
while (twi_addr < HIG_TWI_ADDR) { | ||
Wire.beginTransmission(twi_addr); | ||
if (Wire.endTransmission() == 0) { | ||
if (p_app_mode != nullptr) { | ||
if (twi_addr < (((HIG_TWI_ADDR + 1 - LOW_TWI_ADDR) / 2) + LOW_TWI_ADDR)) { | ||
#if ((defined DEBUG_LEVEL) && (DEBUG_LEVEL >= 1)) | ||
USE_SERIAL.printf_P("[%s] Timonel bootloader found at address: %d (0x%X)\n\r", __func__, twi_addr, twi_addr); | ||
#endif /* DEBUG_LEVEL */ | ||
*p_app_mode = false; | ||
} else { | ||
#if ((defined DEBUG_LEVEL) && (DEBUG_LEVEL >= 1)) | ||
USE_SERIAL.printf_P("[%s] Application firmware found at address: %d (0x%X)\n\r", __func__, twi_addr, twi_addr); | ||
#endif /* DEBUG_LEVEL */ | ||
*p_app_mode = true; | ||
} | ||
} | ||
return twi_addr; | ||
} | ||
delay(DLY_SCAN_BUS); | ||
twi_addr++; | ||
} | ||
return OK; | ||
} | ||
|
||
/* _________________________ | ||
| | | ||
| ScanBus B | | ||
|_________________________| | ||
*/ | ||
// ScanBus (Overload B: Fills an array with the address, firmware and version of all devices connected to the bus) | ||
byte TwiBus::ScanBus(DeviceInfo dev_info_arr[], byte arr_size, byte start_twi_addr) { | ||
// Address 08 to 35: Timonel bootloader | ||
// Address 36 to 63: Application firmware | ||
// Each I2C slave must have a unique bootloader address that corresponds | ||
// to a defined application address, as shown in this table: | ||
// T: |08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35| | ||
// A: |36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|61|62|63| | ||
#if ((defined DEBUG_LEVEL) && (DEBUG_LEVEL >= 1)) | ||
USE_SERIAL.printf_P("\n\r[%s] Scanning TWI bus, searching all the connected devices, please wait ...\n\r", __func__); | ||
#endif /* DEBUG_LEVEL */ | ||
byte found_devices = 0; | ||
byte twi_addr = LOW_TWI_ADDR; | ||
while (twi_addr <= HIG_TWI_ADDR) { | ||
Wire.beginTransmission(twi_addr); | ||
if (Wire.endTransmission() == 0) { | ||
if (twi_addr < (((HIG_TWI_ADDR + 1 - LOW_TWI_ADDR) / 2) + LOW_TWI_ADDR)) { | ||
Timonel tml(twi_addr); | ||
Timonel::Status sts = tml.GetStatus(); | ||
dev_info_arr[found_devices].addr = twi_addr; | ||
if (sts.signature == T_SIGNATURE) { | ||
dev_info_arr[found_devices].firmware = L_TIMONEL; | ||
} else { | ||
dev_info_arr[found_devices].firmware = L_UNKNOWN; | ||
} | ||
dev_info_arr[found_devices].version_major = sts.version_major; | ||
dev_info_arr[found_devices].version_minor = sts.version_minor; | ||
} else { | ||
dev_info_arr[found_devices].addr = twi_addr; | ||
dev_info_arr[found_devices].firmware = L_APP; | ||
dev_info_arr[found_devices].version_major = 0; | ||
dev_info_arr[found_devices].version_minor = 0; | ||
} | ||
found_devices++; | ||
} | ||
//delay(DLY_SCAN_BUS); | ||
twi_addr++; | ||
} | ||
return OK; | ||
} | ||
#else | ||
#pragma GCC warning "TwiBus device discovery functions code included in TWI master!" | ||
#endif /* MULTI_DEVICE */ |
Oops, something went wrong.