From 7f8dfae211a5456ed92a64e7470bb76f5008c15d Mon Sep 17 00:00:00 2001 From: Dmitriy Logachov Date: Wed, 13 Jan 2021 15:10:59 +0500 Subject: [PATCH 1/3] Added the ability to invert SD_DETECT for cardholders with a normally open contact to determine the presence of a card. --- hardware/sdcard/diskio.c | 3 ++- protocol/KISS.c | 9 +++++++++ protocol/KISS.h | 1 + util/Config.c | 11 +++++++++++ util/Config.h | 7 +++++-- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/hardware/sdcard/diskio.c b/hardware/sdcard/diskio.c index 2830ffd..c9644a1 100755 --- a/hardware/sdcard/diskio.c +++ b/hardware/sdcard/diskio.c @@ -16,12 +16,13 @@ #include "diskio.h" #include "device.h" #include "hardware/LED.h" +#include "util/Config.h" /* Port controls (Platform dependent) */ #define CS_LOW() SD_CS_PORT &= ~(_BV(SD_CS_PIN)) /* CS=low */ #define CS_HIGH() SD_CS_PORT |= _BV(SD_CS_PIN) /* CS=high */ -#define MMC_CD ((SD_DETECT_INPUT & _BV(SD_DETECT_PIN))) /* Card detected. yes:true, no:false, default:true */ +#define MMC_CD (config_invert_sddetect == false ? (SD_DETECT_INPUT & _BV(SD_DETECT_PIN)) : (SD_DETECT_INPUT & ~_BV(SD_DETECT_PIN))) /* Card detected. yes:true, no:false, default:true */ #define MMC_WP (false) /* Write protected. yes:true, no:false, default:false */ #define FCLK_SLOW() SPCR = 0x52 /* Set slow clock (F_CPU / 64) */ #define FCLK_FAST() SPCR = 0x50 /* Set fast clock (F_CPU / 2) */ diff --git a/protocol/KISS.c b/protocol/KISS.c index 8ecbffe..e7ca52a 100755 --- a/protocol/KISS.c +++ b/protocol/KISS.c @@ -613,6 +613,15 @@ void kiss_serialCallback(uint8_t sbyte) { if (sbyte == 0x00) { kiss_output_modem_mode(); } + } else if (command == CMD_INVERT_SDDETECT) { + if (sbyte == FESC) { ESCAPE = true; } else { + if (ESCAPE) { + if (sbyte == TFEND) sbyte = FEND; + if (sbyte == TFESC) sbyte = FESC; + ESCAPE = false; + } + config_set_invert_sddetect(sbyte); + } } } } diff --git a/protocol/KISS.h b/protocol/KISS.h index 6b6bb51..e535401 100755 --- a/protocol/KISS.h +++ b/protocol/KISS.h @@ -37,6 +37,7 @@ #define CMD_NMEA 0x40 #define CMD_PRINT_CONFIG 0xF0 #define CMD_RETURN 0xFF +#define CMD_INVERT_SDDETECT 0x15 void kiss_init(AX25Ctx *ax25, Afsk *afsk, Serial *ser); void kiss_messageCallback(AX25Ctx *ctx); diff --git a/util/Config.c b/util/Config.c index 6bf241b..75b9d53 100644 --- a/util/Config.c +++ b/util/Config.c @@ -119,6 +119,7 @@ void config_save_to_eeprom(void) { config_data[i++] = config_gps_mode; config_data[i++] = config_bluetooth_mode; config_data[i++] = config_serial_baudrate; + config_data[i++] = config_invert_sddetect; md5_hash_t checksum; md5(&checksum, &config_data, config_data_size*8); @@ -146,6 +147,7 @@ void config_load_defaults(void) { config_bluetooth_mode = CONFIG_BLUETOOTH_AUTODETECT; config_serial_baudrate = CONFIG_BAUDRATE_115200; config_source = CONFIG_SOURCE_DEFAULT; + config_invert_sddetect = false; } void config_load_from_eeprom(void) { @@ -169,6 +171,7 @@ void config_load_from_eeprom(void) { config_gps_mode = config_data[ADDR_E_GPS_MODE]; config_bluetooth_mode = config_data[ADDR_E_BLUETOOTH_MODE]; config_serial_baudrate = config_data[ADDR_E_SERIAL_BAUDRATE]; + config_invert_sddetect = config_data[ADDR_E_INVERT_SDDETECT]; } bool config_validate_sd(void) { @@ -243,6 +246,14 @@ void config_set_bt_mode(uint8_t mode) { if (mode == CONFIG_BLUETOOTH_REQUIRED) config_bluetooth_mode = CONFIG_BLUETOOTH_REQUIRED; } +void config_set_invert_sddetect(uint8_t invert_sddetect) { + if (invert_sddetect == 0x00) { + config_invert_sddetect = false; + } else { + config_invert_sddetect = true; + } +} + void EEPROM_writebyte(uint16_t addr, uint8_t data) { // Disable interrupts cli(); diff --git a/util/Config.h b/util/Config.h index 69732bd..ef2fee8 100644 --- a/util/Config.h +++ b/util/Config.h @@ -22,8 +22,9 @@ #define ADDR_E_GPS_MODE 0x0D #define ADDR_E_BLUETOOTH_MODE 0x0E #define ADDR_E_SERIAL_BAUDRATE 0x0F -#define ADDR_E_CHECKSUM 0x10 -#define ADDR_E_END 0x20 +#define ADDR_E_INVERT_SDDETECT 0x10 +#define ADDR_E_CHECKSUM 0x11 +#define ADDR_E_END 0x21 #define CONFIG_GPS_OFF 0x00 #define CONFIG_GPS_AUTODETECT 0x01 @@ -73,6 +74,7 @@ uint8_t config_gps_mode; uint8_t config_gps_nmea_output; uint8_t config_bluetooth_mode; uint8_t config_serial_baudrate; +bool config_invert_sddetect; bool config_user_jobs_enabled; bool config_output_diagnostics; @@ -109,6 +111,7 @@ void config_set_log_packets(uint8_t log_packets); void config_set_nmea_output(uint8_t nmea_output); void config_set_gps_mode(uint8_t mode); void config_set_bt_mode(uint8_t mode); +void config_set_invert_sddetect(uint8_t inv_sddetect); void config_enable_diagnostics(void); void config_disable_diagnostics(void); From a0b0cfa97dac91182f7e4525d90d80b9de8f8516 Mon Sep 17 00:00:00 2001 From: Dmitriy Logachov Date: Fri, 15 Jan 2021 22:08:21 +0500 Subject: [PATCH 2/3] Fixed bug of detecting the presence of a card when setting the SD_DETECT inversion. --- hardware/sdcard/diskio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hardware/sdcard/diskio.c b/hardware/sdcard/diskio.c index c9644a1..b3e4541 100755 --- a/hardware/sdcard/diskio.c +++ b/hardware/sdcard/diskio.c @@ -22,7 +22,7 @@ /* Port controls (Platform dependent) */ #define CS_LOW() SD_CS_PORT &= ~(_BV(SD_CS_PIN)) /* CS=low */ #define CS_HIGH() SD_CS_PORT |= _BV(SD_CS_PIN) /* CS=high */ -#define MMC_CD (config_invert_sddetect == false ? (SD_DETECT_INPUT & _BV(SD_DETECT_PIN)) : (SD_DETECT_INPUT & ~_BV(SD_DETECT_PIN))) /* Card detected. yes:true, no:false, default:true */ +#define MMC_CD (config_invert_sddetect == false ? (SD_DETECT_INPUT & _BV(SD_DETECT_PIN)) : ((SD_DETECT_INPUT & _BV(SD_DETECT_PIN)) == 0)) /* Card detected. yes:true, no:false, default:true */ #define MMC_WP (false) /* Write protected. yes:true, no:false, default:false */ #define FCLK_SLOW() SPCR = 0x52 /* Set slow clock (F_CPU / 64) */ #define FCLK_FAST() SPCR = 0x50 /* Set fast clock (F_CPU / 2) */ @@ -579,6 +579,6 @@ void disk_timerproc(void) { } else { s |= (STA_NODISK | STA_NOINIT); /* Socket empty */ } - + Stat = s; /* Update MMC status */ } From 48ef9a625f9f9be0bbcdd37b849b3d855c5a37d4 Mon Sep 17 00:00:00 2001 From: Dmitriy Logachov Date: Sun, 17 Jan 2021 18:20:46 +0500 Subject: [PATCH 3/3] Fixed a bug in the initialization of the bme280 module, which led to a change in PC0 to output instead of input. As a result, the ADC stopped working. This manifested itself as inoperability of packet decoding. --- hardware/BME280.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hardware/BME280.c b/hardware/BME280.c index 11b6d19..af4c19e 100644 --- a/hardware/BME280.c +++ b/hardware/BME280.c @@ -250,7 +250,7 @@ bool bme280_init(uint8_t cs_usrio_pin) { bme280_temperature_fine_adjust = BME280_TEMPERATURE_ADJUSTMENT; - USR_IO_DDR |= bme280_cs_usrio_pin; + USR_IO_DDR |= _BV(bme280_cs_usrio_pin); SPI_DDR |= _BV(SPI_MOSI) | _BV(SPI_CLK); SPI_DDR &= ~(_BV(SPI_MISO));