Skip to content

Commit

Permalink
Merge pull request #155 from nielsonm236/Selectable-Pinout-and-PCF8574
Browse files Browse the repository at this point in the history
20230312 1441 General Release
  • Loading branch information
nielsonm236 authored Mar 12, 2023
2 parents 5774b77 + 99b58d0 commit 4fecbc8
Show file tree
Hide file tree
Showing 12 changed files with 852 additions and 495 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion NetworkModule/.Idea_Groups/Vector_File.grp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Group File Created by IDEA
# Project: <NetworkModule>
# Sun Mar 05 11:25:30 2023
# Sun Mar 12 12:26:59 2023
#
"networkmodule_vector.o"
660 changes: 364 additions & 296 deletions NetworkModule/.Idea_Temp/COBJ.TMP

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions NetworkModule/.Idea_Temp/IDEA.ERR
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ uip_tcpapphub.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libisl0.sm8)strncm.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)fctcpy.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)bmulx.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)cmulx.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)eeprom.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)idiv.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)imul.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)itolx.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)ladc.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lcmp.o:
Expand All @@ -74,20 +71,16 @@ uip_tcpapphub.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lgor.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lgsbc.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lreg.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lsbc.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lsub.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)ltor.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)ludiv.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)ldiv.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lgneg.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lneg.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lumod.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lursh.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lzmp.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)rtol.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)utolx.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)vmul.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)umul.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)xreg.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)xymvx.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)yreg.o:
4 changes: 1 addition & 3 deletions NetworkModule/.Idea_Temp/IDEABLD.BAT
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
REM COMMAND FILE BUILT BY IDEA

REM Sun Mar 05 11:25:26 2023

REM Sun Mar 12 12:26:54 2023
REM
cxstm8 -v -l +strict +debug +modsl0 +split +warn "networkmodule_vector.c"
cxstm8 -v -l +strict +debug +modsl0 +split +warn "bme280.c" "ds18b20.c" "enc28j60.c" "gpio.c" "httpd.c" "i2c.c" "main.c" "mqtt.c" "mqtt_pal.c" "pcf8574.c" "spi.c" "timer.c" "uart.c" "uip.c" "uip_arp.c" "uip_tcpapphub.c"
Expand Down
18 changes: 9 additions & 9 deletions NetworkModule/Gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// extern uint8_t stored_magic1; // LSB Magic Number
extern uint8_t stored_pin_control[16]; // STM8 per pin control settings
// stored in EEPROM
extern uint8_t stored_hardware_options; // Hardware options stored in EEPROM
extern uint8_t stored_options1; // Additional options stored in EEPROM

// io_map_offset defines the user selected IO pinout map.
// io_map_offset = 0 for the first 16 io_map definitions
Expand Down Expand Up @@ -199,9 +199,9 @@ void gpio_init(void)
// If an alternate Pinout Option is selected it must be selected before any
// GPIO settings are applied.
//
// (stored_hardware_options & 0x07) = 1 for the first 16 io_map definitions
// (stored_hardware_options & 0x07) = 2 for the second 16 io_map definitions
// (stored_hardware_options & 0x07) = 3 for the third 16 io_map definitions
// (stored_options1 & 0x07) = 1 for the first 16 io_map definitions
// (stored_options1 & 0x07) = 2 for the second 16 io_map definitions
// (stored_options1 & 0x07) = 3 for the third 16 io_map definitions
// io_map_offset defines the user selected IO pinout map.
// io_map_offset = 0 for the first 16 io_map definitions
// io_map_offset = 16 for the second 16 io_map definitions
Expand All @@ -217,18 +217,18 @@ void gpio_init(void)
// If ISC_SUPPORT is enabled then Option 1 must be used. Set a flag.
i = 1;
#endif I2C_SUPPORT == 1
j = (uint8_t)(stored_hardware_options & 0x07);
j = (uint8_t)(stored_options1 & 0x07);
if (j > 0 && j < 4 && i == 0) {
// If stored_hardware_options is valid update io_map_offset
io_map_offset = (uint8_t)(((stored_hardware_options & 0x07) - 1) * 16);
// If stored_options1 is valid update io_map_offset
io_map_offset = (uint8_t)(((stored_options1 & 0x07) - 1) * 16);
}
else {
// Else use Option 1
io_map_offset = 0;
j = (uint8_t)(stored_hardware_options & 0xf8);
j = (uint8_t)(stored_options1 & 0xf8);
j |= 0x01;
unlock_eeprom();
stored_hardware_options = j;
stored_options1 = j;
lock_eeprom();
}
}
Expand Down
90 changes: 42 additions & 48 deletions NetworkModule/Main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
//---------------------------------------------------------------------------//
//---------------------------------------------------------------------------//
// IMPORTANT: The code_revision must be exactly 13 characters
const char code_revision[] = "20230305 1816"; // Normal Release Revision
const char code_revision[] = "20230312 1441"; // Normal Release Revision
// const char code_revision[] = "20210529 1999"; // Browser Only test build
// const char code_revision[] = "20210529 2999"; // MQTT test build
// const char code_revision[] = "20210531 CU01"; // Code Uploader test build
Expand Down Expand Up @@ -140,11 +140,15 @@ uint8_t stack_limit2;
@eeprom uint8_t stored_uip_ethaddr_oct[6]; // Bytes 24-29 MAC MSB
@eeprom uint8_t stored_EEPROM_revision2; // Byte 23 EEPROM revision
@eeprom uint8_t stored_EEPROM_revision1; // Byte 22 EEPROM revision
@eeprom uint8_t stored_hardware_options; // Byte 21 Hardware Options
@eeprom uint8_t stored_options1; // Byte 21 Additional Options
// Bit 7: Undefined, 0 only
// Bit 6: Undefined, 0 only
// Bit 5: Undefined, 0 only
// Bit 4: Undefined, 0 only
// Bit 4: Short Form Option
// 0 = Original format all '0'
// and '1'
// 1 = Show '-' for Disabled
// pins
// Bit 3: PCF8574 present
// 0 = No PCF8574 detected or
// PCF8574 not supported
Expand Down Expand Up @@ -772,7 +776,7 @@ STM8_display_pin_control();
if (I2C_PCF8574_1_WRITE_CMD) {
// A PCF8574 or PCF8574A was found as indicated by a non-zero value in
// variable I2C_PCF8574_1_WRITE_CMD after running PCF8574_init().
// Update the stored_hardware_options byte in EEPROM.
// Update the stored_options1 byte in EEPROM.

#if DEBUG_SUPPORT == 7 || DEBUG_SUPPORT == 15
// UARTPrintf("Main - Found PCF8574 at ");
Expand All @@ -783,11 +787,11 @@ STM8_display_pin_control();

{
uint8_t j;
j = stored_hardware_options;
j = stored_options1;
if ((j & 0x08) != 0x08) {
j |= 0x08;
unlock_eeprom();
stored_hardware_options = j;
stored_options1 = j;
lock_eeprom();
}
}
Expand All @@ -798,11 +802,11 @@ STM8_display_pin_control();
#endif // DEBUG_SUPPORT == 7 || DEBUG_SUPPORT == 15
{
uint8_t j;
j = stored_hardware_options;
j = stored_options1;
if ((j & 0x08) == 0x08) {
j &= (uint8_t)(~0x08);
unlock_eeprom();
stored_hardware_options = j;
stored_options1 = j;
lock_eeprom();
}
}
Expand All @@ -813,11 +817,11 @@ STM8_display_pin_control();
// PCF8574 not supported. Make sure the hardware option is off.
{
uint8_t j;
j = stored_hardware_options;
j = stored_options1;
if ((j & 0x08) == 0x08) {
j &= (uint8_t)~0x08;
unlock_eeprom();
stored_hardware_options = j;
stored_options1 = j;
lock_eeprom();
}
}
Expand Down Expand Up @@ -2082,9 +2086,8 @@ void mqtt_startup(void)
if (pin_ptr == 16) {
#endif // PCF8574_SUPPORT == 0
#if PCF8574_SUPPORT == 1
// if (pin_ptr == 24) {
if ((!(stored_hardware_options & 0x08) && (pin_ptr == 16))
|| ((stored_hardware_options & 0x08) && (pin_ptr == 24))) {
if ((!(stored_options1 & 0x08) && (pin_ptr == 16))
|| ((stored_options1 & 0x08) && (pin_ptr == 24))) {
#endif // PCF8574_SUPPORT == 1
pin_ptr = 1;
auto_discovery = DEFINE_OUTPUTS;
Expand All @@ -2101,9 +2104,8 @@ void mqtt_startup(void)
if (pin_ptr == 16) {
#endif // PCF8574_SUPPORT == 0
#if PCF8574_SUPPORT == 1
// if (pin_ptr == 24) {
if ((!(stored_hardware_options & 0x08) && (pin_ptr == 16))
|| ((stored_hardware_options & 0x08) && (pin_ptr == 24))) {
if ((!(stored_options1 & 0x08) && (pin_ptr == 16))
|| ((stored_options1 & 0x08) && (pin_ptr == 24))) {
#endif // PCF8574_SUPPORT == 1
pin_ptr = 1;
auto_discovery = DEFINE_OUTPUTS;
Expand Down Expand Up @@ -2136,9 +2138,8 @@ void mqtt_startup(void)
if (pin_ptr == 16) {
#endif // PCF8574_SUPPORT == 0
#if PCF8574_SUPPORT == 1
// if (pin_ptr == 24) {
if ((!(stored_hardware_options & 0x08) && (pin_ptr == 16))
|| ((stored_hardware_options & 0x08) && (pin_ptr == 24))) {
if ((!(stored_options1 & 0x08) && (pin_ptr == 16))
|| ((stored_options1 & 0x08) && (pin_ptr == 24))) {
#endif // PCF8574_SUPPORT == 1
pin_ptr = 1;
auto_discovery = DEFINE_DISABLED;
Expand All @@ -2153,9 +2154,8 @@ void mqtt_startup(void)
if (pin_ptr == 16) {
#endif // PCF8574_SUPPORT == 0
#if PCF8574_SUPPORT == 1
// if (pin_ptr == 24) {
if ((!(stored_hardware_options & 0x08) && (pin_ptr == 16))
|| ((stored_hardware_options & 0x08) && (pin_ptr == 24))) {
if ((!(stored_options1 & 0x08) && (pin_ptr == 16))
|| ((stored_options1 & 0x08) && (pin_ptr == 24))) {
#endif // PCF8574_SUPPORT == 1
pin_ptr = 1;
auto_discovery = DEFINE_DISABLED;
Expand All @@ -2182,9 +2182,8 @@ void mqtt_startup(void)
if (pin_ptr == 16) {
#endif // PCF8574_SUPPORT == 0
#if PCF8574_SUPPORT == 1
// if (pin_ptr == 24) {
if ((!(stored_hardware_options & 0x08) && (pin_ptr == 16))
|| ((stored_hardware_options & 0x08) && (pin_ptr == 24))) {
if ((!(stored_options1 & 0x08) && (pin_ptr == 16))
|| ((stored_options1 & 0x08) && (pin_ptr == 24))) {
#endif // PCF8574_SUPPORT == 1
auto_discovery = DEFINE_TEMP_SENSORS;
}
Expand All @@ -2199,9 +2198,8 @@ void mqtt_startup(void)
if (pin_ptr == 16) {
#endif // PCF8574_SUPPORT == 0
#if PCF8574_SUPPORT == 1
// if (pin_ptr == 24) {
if ((!(stored_hardware_options & 0x08) && (pin_ptr == 16))
|| ((stored_hardware_options & 0x08) && (pin_ptr == 24))) {
if ((!(stored_options1 & 0x08) && (pin_ptr == 16))
|| ((stored_options1 & 0x08) && (pin_ptr == 24))) {
#endif // PCF8574_SUPPORT == 1
auto_discovery = DEFINE_TEMP_SENSORS;
}
Expand Down Expand Up @@ -2863,9 +2861,8 @@ void publish_callback(void** unused, struct mqtt_response_publish *published)
for (i=0; i<16; i++) {
#endif // PCF8574_SUPPORT == 0
#if PCF8574_SUPPORT == 1
// for (i=0; i<24; i++) {
if (!(stored_hardware_options & 0x08)) k = 16;
else k = 24;
if ((stored_options1 & 0x08)) k = 24;
else k = 16;
for (i=0; i<k; i++) {
#endif // PCF8574_SUPPORT == 1
#if LINKED_SUPPORT == 0
Expand All @@ -2885,9 +2882,8 @@ void publish_callback(void** unused, struct mqtt_response_publish *published)
for (i=0; i<16; i++) {
#endif // PCF8574_SUPPORT == 0
#if PCF8574_SUPPORT == 1
// for (i=0; i<24; i++) {
if (!(stored_hardware_options & 0x08)) k = 16;
else k = 24;
if ((stored_options1 & 0x08)) k = 24;
else k = 16;
for (i=0; i<k; i++) {
#endif // PCF8574_SUPPORT == 1
#if LINKED_SUPPORT == 0
Expand Down Expand Up @@ -2976,19 +2972,17 @@ void publish_callback(void** unused, struct mqtt_response_publish *published)
// "state-req" detected
// Format is:
// state-req
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// WARNING: To save flash space I don't check every sub-topic character.
// But I also don't clear the uip_buf. So, I could pick up on stuff left
// by a prevous message if not careful. In this limited application I can
// get away with it, but this can trip me up in the future if more
// messages are added.
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
pBuffer += 8;
if (*pBuffer == 'q') {
*pBuffer = '0'; // Destroy 'q' in buffer so subsequent "state"
// messages won't be misinterpreted
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// WARNING: To save flash space I don't check every
// sub-topic character. But I also don't clear the
// uip_buf. So, I could pick up on stuff left by a
// prevous message if not careful. In this limited
// application I can get away with it, but this can
// trip me up in the future if more messages are
// added.
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
state_request = STATE_REQUEST_RCVD;
}
}
Expand Down Expand Up @@ -3078,7 +3072,7 @@ void publish_outbound(void)
j = 0x8000;
#endif // PCF8574_SUPPORT == 0
#if PCF8574_SUPPORT == 1
if (stored_hardware_options & 0x08) {
if (stored_options1 & 0x08) {
i = 23;
j = 0x00800000;
}
Expand Down Expand Up @@ -3316,7 +3310,7 @@ void publish_pinstate_all(void)
for (i=0; i<16; i++) {
#endif // PCF8574_SUPPORT == 0
#if PCF8574_SUPPORT == 1
if (stored_hardware_options & 0x08) m = 24;
if (stored_options1 & 0x08) m = 24;
else m = 16;
for (i=0; i<m; i++) {
#endif // PCF8574_SUPPORT == 1
Expand Down Expand Up @@ -3751,7 +3745,7 @@ void check_eeprom_settings(void)
} // 20 bytes

// 1 byte stored hardware options
stored_hardware_options = 0;
stored_options1 = 0;

// Skip 2 bytes (the EEPROM revision bytes)

Expand Down Expand Up @@ -4554,7 +4548,7 @@ void check_runtime_changes(void)
// User has requested that DS18B20 functionality be enabled, or DS18B20
// was already enabled in the config settings. DS18B20 is only allowed if
// pinout Option 1 is being used.
if ((stored_hardware_options & 0x07) > 1) {
if ((stored_options1 & 0x07) > 1) {
Pending_config_settings &= (uint8_t)~0x08;
// If DS18B20 is enabled in the stored_config_settings it will be
// disabled in code further below.
Expand All @@ -4564,7 +4558,7 @@ void check_runtime_changes(void)
// User has requested that BME280 functionality be enabled, or BME280
// was already enabled in the config settings. BME280 is only allowed if
// pinout Option 1 is being used.
if ((stored_hardware_options & 0x07) > 1) {
if ((stored_options1 & 0x07) > 1) {
Pending_config_settings &= (uint8_t)~0x20;
// If DS18B20 is enabled in the stored_config_settings it will be
// disabled in code further below.
Expand Down
Loading

0 comments on commit 4fecbc8

Please sign in to comment.