aboutsummaryrefslogtreecommitdiff
path: root/lib/pbdrv/pb-mod.c
blob: 0342391489198fbd16ace0bf5d544ce919116685 (plain)
1
2
3
4
5
6
7
8
9
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
36
37
38
39
40
41
42
43
44
#include "pb-buf.h"
#include "pb-msg.h"
#include "pb-types.h"
#include "pb-mod.h"
#include "pb-route.h"

//! fallback module name
__weak const char * PB_MOD_NAME = "???";

//! [private] placeholder global state variable
static pb_global_state_t _global_state = PB_GS_NOINIT;

__weak pb_global_state_t pb_hook_mod_state_read() {
	return _global_state;
}

__weak void pb_hook_mod_state_write(pb_global_state_t state) {
	_global_state = state;
}

__weak void pb_i2c_recv(const uint8_t * data, size_t sz) {
	if (pb_hook_i2c_recv(data, sz)) return;

	pb_buf_t buf = {
		.data = (char *) data,
		.size = sz,
	};
	pb_msg_t * msg = pb_msg_read(&buf);
	if (msg == NULL) return; // invalid message
	if (msg->cmd == NULL) return; // invalid message
	
	pb_route_msg(msg);

	pb_msg_free(msg);
}

__weak bool pb_hook_i2c_recv(const uint8_t * data, size_t sz) {
	return false;
}

__weak bool pb_hook_i2c_send(i2c_addr_t i2c_addr, const uint8_t * data, size_t sz) {
	return false;
}