Compare commits

...
3 Commits
Author SHA1 Message Date
aZholtikov a795dfedc7 doc: updated readme 2026-10-21 12:02:04 +03:00
aZholtikov 0d2625df7f doc: added general configuration library 2026-10-21 08:35:03 +03:00
aZholtikov bdecf0331c perf: reworked sleep logic 2026-10-21 08:21:02 +03:00
4 changed files with 34 additions and 14 deletions

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
.vscode .vscode
.DS_Store .DS_Store
build build
.pio
+1 -7
View File
@@ -6,7 +6,7 @@
2. Power consumption in the sleep mode approximately 2 uA. 2. Power consumption in the sleep mode approximately 2 uA.
3. Transmits device identifier and battery voltage level on each touch event. 3. Transmits device identifier and battery voltage level on each touch event.
4. Battery measurement through internal ADC with 1.1 V bandgap reference. 4. Battery measurement through internal ADC with 1.1 V bandgap reference.
5. Wake-up from power-down mode by external interrupt on falling edge. 5. Wake-up from power-down mode by external interrupt on rising edge.
6. Supports ATMega168, ATMega168P, ATMega168PB, ATMega328, ATMega328P, ATMega328PB. 6. Supports ATMega168, ATMega168P, ATMega168PB, ATMega328, ATMega328P, ATMega328PB.
7. Easy installation into any standard touch pad enclosure. 7. Easy installation into any standard touch pad enclosure.
@@ -25,9 +25,3 @@ In an existing PlatformIO project, run the following command to install the firm
cd your_project cd your_project
git clone https://github.com/aZholtikov/zh_avr_touch_pad git clone https://github.com/aZholtikov/zh_avr_touch_pad
``` ```
In the `platformio.ini`, select the target microcontroller environment and upload:
```bash
pio run -e ATmega328P -t upload
```
+12
View File
@@ -11,6 +11,8 @@ board_fuses.efuse = 0x07
upload_flags = upload_flags =
-Pusb -Pusb
-e -e
lib_deps =
https://github.com/aZholtikov/zh_rf_config
[env:ATmega168P] [env:ATmega168P]
platform = atmelavr platform = atmelavr
@@ -25,6 +27,8 @@ board_fuses.efuse = 0x07
upload_flags = upload_flags =
-Pusb -Pusb
-e -e
lib_deps =
https://github.com/aZholtikov/zh_rf_config
[env:ATmega168PB] [env:ATmega168PB]
platform = atmelavr platform = atmelavr
@@ -39,6 +43,8 @@ board_fuses.efuse = 0x07
upload_flags = upload_flags =
-Pusb -Pusb
-e -e
lib_deps =
https://github.com/aZholtikov/zh_rf_config
[env:ATmega328] [env:ATmega328]
platform = atmelavr platform = atmelavr
@@ -53,6 +59,8 @@ board_fuses.efuse = 0x07
upload_flags = upload_flags =
-Pusb -Pusb
-e -e
lib_deps =
https://github.com/aZholtikov/zh_rf_config
[env:ATmega328P] [env:ATmega328P]
platform = atmelavr platform = atmelavr
@@ -67,6 +75,8 @@ board_fuses.efuse = 0x07
upload_flags = upload_flags =
-Pusb -Pusb
-e -e
lib_deps =
https://github.com/aZholtikov/zh_rf_config
[env:ATmega328PB] [env:ATmega328PB]
platform = atmelavr platform = atmelavr
@@ -81,3 +91,5 @@ board_fuses.efuse = 0x07
upload_flags = upload_flags =
-Pusb -Pusb
-e -e
lib_deps =
https://github.com/aZholtikov/zh_rf_config
+20 -7
View File
@@ -3,6 +3,7 @@
#include "avr/fuse.h" #include "avr/fuse.h"
#include "avr/interrupt.h" #include "avr/interrupt.h"
#include "util/delay.h" #include "util/delay.h"
#include "zh_rf_config.h"
#if defined(__AVR_ATmega328PB__) #if defined(__AVR_ATmega328PB__)
#ifndef SPCR #ifndef SPCR
@@ -31,7 +32,6 @@
#define GATEWAY_CHANNEL 120 #define GATEWAY_CHANNEL 120
#define GATEWAY_ADDRESS 0xDDEEFF #define GATEWAY_ADDRESS 0xDDEEFF
#define DEVICE_ID 6 #define DEVICE_ID 6
#define DEVICE_TYPE 4
#define NRF_CMD_W_REGISTER 0x20 #define NRF_CMD_W_REGISTER 0x20
#define NRF_CMD_W_TX_PAYLOAD 0xA0 #define NRF_CMD_W_TX_PAYLOAD 0xA0
@@ -60,7 +60,7 @@
/** /**
* @brief Initialize INT1 external interrupt for the touch-pad wake-up signal. * @brief Initialize INT1 external interrupt for the touch-pad wake-up signal.
* *
* Configures PD3 as a falling-edge triggered external interrupt source and * Configures PD3 as a rising-edge triggered external interrupt source and
* enables the INT1 interrupt mask bit. The ISR sets the send_request flag * enables the INT1 interrupt mask bit. The ISR sets the send_request flag
* to trigger a radio transmission from the main loop. * to trigger a radio transmission from the main loop.
*/ */
@@ -164,6 +164,8 @@ static float zh_get_battery_voltage(void);
static volatile uint8_t send_request = 0; static volatile uint8_t send_request = 0;
zh_rf_sensor_transmitted_data_t transmitted_data = {DEVICE_ID, ZH_RF_SENSOR_TOUCH_SWITCH, 0, 0, 0, 0, 0};
int main(void) int main(void)
{ {
cli(); cli();
@@ -171,19 +173,28 @@ int main(void)
zh_spi_init(); zh_spi_init();
zh_nrf24_init(); zh_nrf24_init();
set_sleep_mode(SLEEP_MODE_PWR_DOWN); set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sei(); sei();
for (;;) for (;;)
{ {
if (send_request == 1) if (send_request == 1)
{ {
cli();
send_request = 0; send_request = 0;
int16_t data[] = {DEVICE_ID, DEVICE_TYPE, (int16_t)(zh_get_battery_voltage() * 100.0), 0, 0, 0, 0}; sei();
zh_nrf24_send((uint8_t *)data, sizeof(data)); transmitted_data.battery_voltage = (int16_t)(zh_get_battery_voltage() * 100.0);
zh_nrf24_send((uint8_t *)&transmitted_data, sizeof(transmitted_data));
} }
else else
{ {
sleep_cpu(); cli();
if (send_request == 0)
{
sleep_enable();
sei();
sleep_cpu();
}
sei();
sleep_disable();
} }
} }
return 0; return 0;
@@ -225,6 +236,8 @@ static void zh_nrf24_init(void)
_delay_ms(100); _delay_ms(100);
DDRB |= (1 << PB1); DDRB |= (1 << PB1);
PORTB &= ~(1 << PB1); PORTB &= ~(1 << PB1);
DDRD &= ~(1 << PD2);
PORTD |= (1 << PD2);
uint64_t gateway_address = GATEWAY_ADDRESS; uint64_t gateway_address = GATEWAY_ADDRESS;
zh_nrf24_write_register(NRF_REG_CONFIG, 0x00); zh_nrf24_write_register(NRF_REG_CONFIG, 0x00);
zh_nrf24_write_register(NRF_REG_EN_AA, 0x01); zh_nrf24_write_register(NRF_REG_EN_AA, 0x01);
@@ -249,7 +262,7 @@ static void zh_nrf24_send(uint8_t *buf, uint8_t size)
uint8_t count = 0; uint8_t count = 0;
while ((PIND & (1 << PD2)) != 0) while ((PIND & (1 << PD2)) != 0)
{ {
if (++count > 50) if (++count > 100)
{ {
break; break;
} }