Skip to content

Commit fa5abfb

Browse files
committed
Merge branch 'hal' into hal-build
2 parents 94deec6 + 7b82d3a commit fa5abfb

File tree

19 files changed

+95
-78
lines changed

19 files changed

+95
-78
lines changed

device_db.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ MOES_SWITCHES_TS0014:
787787
stock_converter_model: TS0014
788788
override_z2m_device: null
789789
zb_module: ZS3L
790-
config_str: mrduubod;Moes-4-gang;SB6u;RB5;ID3;SC1u;RB4;ID7;SC4u;RD2;IC0;M;
790+
config_str: mrduubod;Moes-4-gang;SA0u;RA4;IA6;SA3u;RC0;IA5;SB0u;RC1;IC2;SB1u;RD1;ID0;M;
791791
alt_config_str: null
792792
old_manufacturer_names: null
793793
old_zb_models: null

docs/contribute/building.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ Two branches are recommended to avoid conflicts between generated files.
4040
8. Add the updated converters/quirks to your Z2M/ZHA instance
4141
(if new ones were generated)
4242
9. Prepare the update
43+
4344
- For wireless update, use the corresponding index in your OTA settings
4445
(user + **build_branch** + device_type)
4546
- For wire update, get the binary file for your device
46-
(`bin/DEVICE_TYPE/BOARD/tlc_switch.bin`)
47+
(telink uses `bin/DEVICE_TYPE/BOARD/tlc_switch-X.Y.Z-<commit-hash>.bin`,
48+
silabs uses `bin/DEVICE_TYPE/BOARD/tlc_switch-X.Y.Z-<commit-hash>.s37`)
49+
4750
10. Perform device update and test: [readme.md # Flashing](/readme.md#-flashing)
4851
11. Create a Pull Request (**code_branch****romasku/main**)
4952
12. Check the unit tests result

src/base_components/led.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "hal/tasks.h"
55
#include "hal/timer.h"
66

7+
#include <stdio.h>
8+
79
void led_init(led_t *led) { led_off(led); }
810

911
void led_on(led_t *led) {
@@ -38,6 +40,11 @@ static void led_blink_handler(void *arg) {
3840

3941
void led_blink(led_t *led, uint16_t on_time_ms, uint16_t off_time_ms,
4042
uint16_t times) {
43+
if (led->blink_times_left != 0) {
44+
led->blink_times_left = times;
45+
return;
46+
}
47+
4148
hal_gpio_write(led->pin, led->on_high);
4249
led->on = 1;
4350
led->blink_time_on = on_time_ms;

src/base_components/network_indicator.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ void network_indicator_connected(network_indicator_t *indicator) {
88
void network_indicator_from_manual_state(network_indicator_t *indicator) {
99
led_t **led = indicator->leds;
1010

11-
while (*led != NULL) {
11+
while (*led != NULL && (led - indicator->leds) < 4) {
1212
(*led)->blink_times_left = 0;
1313
if (indicator->has_dedicated_led) {
1414
if (indicator->manual_state_when_connected) {
@@ -24,7 +24,7 @@ void network_indicator_from_manual_state(network_indicator_t *indicator) {
2424
void network_indicator_commission_success(network_indicator_t *indicator) {
2525
led_t **led = indicator->leds;
2626

27-
while (*led != NULL) {
27+
while (*led != NULL && (led - indicator->leds) < 4) {
2828
led_blink(*led, 500, 500, 7);
2929
led++;
3030
}
@@ -33,7 +33,7 @@ void network_indicator_commission_success(network_indicator_t *indicator) {
3333
void network_indicator_not_connected(network_indicator_t *indicator) {
3434
led_t **led = indicator->leds;
3535

36-
while (*led != NULL) {
36+
while (*led != NULL && (led - indicator->leds) < 4) {
3737
if ((*led)->blink_times_left != LED_BLINK_FOREVER) {
3838
led_blink(*led, 500, 500, LED_BLINK_FOREVER);
3939
}

src/device_config/config_parser.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ uint32_t parse_int(const char *s);
5757
char *seek_until(char *cursor, char needle);
5858
char *extract_next_entry(char **cursor);
5959

60-
void on_reset_clicked(void *_) { reset_all(); }
60+
void on_reset_clicked(void *_) { hal_factory_reset(); }
6161

6262
void parse_config() {
6363
device_config_read_from_nv();
@@ -187,6 +187,9 @@ void parse_config() {
187187

188188
periferals_init();
189189

190+
printf("Initializing Zigbee with %d switches and %d relays\r\n",
191+
switch_clusters_cnt, relay_clusters_cnt);
192+
190193
uint8_t total_endpoints = switch_clusters_cnt + relay_clusters_cnt;
191194

192195
hal_zigbee_cluster *cluster_ptr = clusters;
@@ -234,10 +237,13 @@ void parse_config() {
234237
*cursor = ';';
235238
}
236239
}
240+
241+
printf("Config parsed successfully\r\n");
237242
}
238243

239244
void network_indicator_on_network_status_change(
240245
hal_zigbee_network_status_t new_status) {
246+
printf("Network status changed to %d\r\n", new_status);
241247
if (new_status == HAL_ZIGBEE_NETWORK_JOINED) {
242248
network_indicator_connected(&network_indicator);
243249
} else {
@@ -258,23 +264,6 @@ void periferals_init() {
258264
network_indicator_on_network_status_change);
259265
}
260266

261-
void init_reporting() {
262-
// u32 reportableChange = 1;
263-
//
264-
// for (int index = 0; index < relay_clusters_cnt; index++)
265-
// {
266-
// bdb_defaultReportingCfg(
267-
// switch_clusters_cnt + index + 1,
268-
// HA_PROFILE_ID,
269-
// ZCL_CLUSTER_GEN_ON_OFF,
270-
// ZCL_ATTRID_ONOFF,
271-
// 0,
272-
// 60,
273-
// (u8 *)&reportableChange
274-
// );
275-
// }
276-
}
277-
278267
// Helper functions
279268

280269
char *seek_until(char *cursor, char needle) {

src/device_config/reset.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
__attribute__((noreturn)) void reset_all() {
88
printf("RESET ALL!\r\n");
99
hal_nvm_clear_all();
10+
hal_factory_reset();
1011
hal_system_reset();
1112
}

src/hal/system.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
*/
77
void __attribute__((noreturn)) hal_system_reset(void);
88

9+
void hal_factory_reset(void);
10+
911
#endif /* _HAL_SYSTEM_H_ */

src/silabs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ DEBUG ?= 0
1212

1313

1414
DEVICE_TYPE ?= router
15-
CONFIG_STR ?= jl7qyupf;TS0012-custom;SA0u;SA3u;SB0u;SB1u;RD0;RC2;RA5;RA6;
15+
CONFIG_STR ?= mrduubod;Moes-4-gang;SA0u;RA4;IA6;SA3u;RC0;IA5;SB0u;RC1;IC2;SB1u;RD1;ID0;M;
1616
MANUFACTURER_ID = 4169 # 0x1049, can be overridden via .zap file only
1717
IMAGE_TYPE ?= 54179
1818

src/silabs/hal/gpio.c

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44
#include "em_gpio.h"
55
#include "gpiointerrupt.h"
66
#include <stdbool.h>
7+
#include <stddef.h>
78
#include <string.h>
89

910
#include "zigbee_app_framework_event.h"
1011

1112
#include "hal/gpio.h"
13+
#include <stdio.h>
14+
15+
// Get container structure from embedded member pointer
16+
#define container_of(ptr, type, member) \
17+
((type *)((char *)(ptr) - offsetof(type, member)))
1218

1319
// ------ Encoding helpers ------
1420
// hal_gpio_pin_t: upper byte = port index (A=0, B=1, ...), lower byte = pin
@@ -47,7 +53,6 @@ static void hal_gpio_ensure_gpioint(void) {
4753
// ------ Per-interrupt bookkeeping ------
4854
typedef struct {
4955
bool in_use;
50-
uint8_t em4wu_int_no;
5156
hal_gpio_pin_t hal_pin;
5257
uint8_t pull_dir; // for EM4WU polarity selection
5358
gpio_callback_t user_cb;
@@ -83,16 +88,9 @@ static void _dispatch_regular(uint8_t intNo, void *ctx) {
8388
}
8489
}
8590

86-
static void _dispatch_em4wu(uint8_t intNo, void *ctx) {
87-
(void)intNo;
88-
int_slot_t *slot = (int_slot_t *)ctx;
89-
if (slot) {
90-
sl_zigbee_af_event_set_active(&slot->af_event);
91-
}
92-
}
93-
94-
static void _af_event_handler(sli_zigbee_event_t *event) {
95-
int_slot_t *slot = (int_slot_t *)event->data;
91+
static void _af_event_handler(sl_zigbee_af_event_t *event) {
92+
// Get int_slot_t from embedded af_event field
93+
int_slot_t *slot = container_of(event, int_slot_t, af_event);
9694
if (slot->user_cb) {
9795
slot->user_cb(slot->hal_pin, slot->arg);
9896
}
@@ -172,7 +170,6 @@ void hal_gpio_callback(hal_gpio_pin_t gpio_pin, gpio_callback_t callback,
172170
slot->user_cb = callback;
173171
slot->arg = arg;
174172
sl_zigbee_af_isr_event_init(&slot->af_event, _af_event_handler);
175-
slot->af_event.data = (uint32_t)slot;
176173

177174
GPIO_Mode_TypeDef mode = GPIO_PinModeGet(port, pin_num);
178175
if (mode == gpioModeInputPull) {
@@ -185,25 +182,11 @@ void hal_gpio_callback(hal_gpio_pin_t gpio_pin, gpio_callback_t callback,
185182
slot->pull_dir = HAL_GPIO_PULL_NONE;
186183
}
187184

188-
// 1) Register regular edge-sensitive callback (both edges)
185+
// Register regular edge-sensitive callback (both edges)
189186
unsigned int reg_int = GPIOINT_CallbackRegisterExt(
190187
line, (GPIOINT_IrqCallbackPtrExt_t)_dispatch_regular, slot);
191188
EFM_ASSERT(reg_int != INTERRUPT_UNAVAILABLE);
192189
GPIO_ExtIntConfig(port, pin_num, line, true, true, true);
193-
194-
// 2) Try to also register an EM4WU (level-sensitive) wake-up on this pin.
195-
// If unsupported, GPIOINT_EM4WUCallbackRegisterExt returns
196-
// INTERRUPT_UNAVAILABLE. Polarity: wake on the *active* level.
197-
bool active_is_high = (slot->pull_dir == HAL_GPIO_PULL_DOWN);
198-
unsigned int em4_line = GPIOINT_EM4WUCallbackRegisterExt(
199-
port, pin_num, (GPIOINT_IrqCallbackPtrExt_t)_dispatch_em4wu, slot);
200-
if (em4_line != INTERRUPT_UNAVAILABLE) {
201-
GPIO_EM4WUExtIntConfig(port, pin_num, em4_line, active_is_high ? 1U : 0U,
202-
true);
203-
slot->em4wu_int_no = em4_line;
204-
} else {
205-
slot->em4wu_int_no = LINE_MISSING;
206-
}
207190
}
208191

209192
// (Optional) helper to unregister an interrupt if you add
@@ -214,19 +197,12 @@ void hal_gpio_unreg_callback(hal_gpio_pin_t gpio_pin) {
214197
GPIO_Port_TypeDef port = hal_port_from_index(port_idx);
215198

216199
uint8_t int_no = LINE_MISSING;
217-
uint8_t em4wu_int_no = LINE_MISSING;
218200
for (uint8_t i = 0; i < MAX_INT_LINES; i++) {
219201
if (s_slots[i].in_use && s_slots[i].hal_pin == gpio_pin) {
220202
int_no = i;
221-
em4wu_int_no = s_slots[i].em4wu_int_no;
222203
}
223204
}
224205

225-
if (em4wu_int_no != LINE_MISSING) {
226-
GPIO_EM4WUExtIntConfig(port, pin_num, em4wu_int_no, 0, false);
227-
GPIOINT_EM4WUCallbackUnRegister(em4wu_int_no);
228-
}
229-
230206
if (int_no != LINE_MISSING) {
231207
GPIO_ExtIntConfig(port, pin_num, int_no, false, false, false);
232208
GPIOINT_CallbackUnRegister(int_no);

src/silabs/hal/system.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#include "hal/system.h"
2-
#include <stdint.h>
3-
#include <stdbool.h>
2+
#include "app/framework/include/af.h"
3+
#include "hal/zigbee.h"
44
#include "micro-common.h"
5+
#include <stdbool.h>
6+
#include <stdint.h>
7+
8+
void hal_system_reset(void) { halReboot(); }
59

6-
void hal_system_reset(void) {
7-
halReboot();
10+
void hal_factory_reset(void) {
11+
hal_zigbee_leave_network();
12+
sl_zigbee_clear_binding_table();
813
}

0 commit comments

Comments
 (0)