aboutsummaryrefslogtreecommitdiff
path: root/lib/pbdrv/pb-mod.h
blob: c4629a67ec2069818b8b91d060a9f448f27cdf12 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once

/**
 * \file puzzle bus driver implementation
 *
 * Most \c pb_* functions have a weak implementation, which may be overwritten
 * by a custom implementation. This allows you to use the default
 * implementation where possible, and only implement extensions required for
 * your puzzle module. Please see spec.adoc for more information about how to
 * use the puzzle bus driver library.
 */

#include "pb-types.h"

#ifdef __cplusplus
extern "C" {
#endif

//! puzzle module name (optional, default = "???")
extern const char * PB_MOD_NAME;
//! puzzle module bus address (required)
extern const i2c_addr_t PB_MOD_ADDR;

/**
 * \brief handle a received message from the I2C bus (puzzle bus)
 *
 * This function attempts to parse an I2C message as a puzzle bus message, and
 * calls the appropriate handler for the message if it is considered valid.
 *
 * \param buf pointer to message content
 * \param sz size of \p buf
 *
 * \note This function should not be directly called from an ISR. Please use
 * FreeRTOS's \c xTimerPendFunctionCallFromISR() or a similar scheduler-based
 * deferred function call mechanism instead.
 */
void pb_i2c_recv(const uint8_t * buf, size_t sz);
/**
 * \brief send a message in master-mode on the I2C bus (puzzle bus)
 *
 * This function sends an I2C message to the address specified by \p i2c_addr.
 *
 * \param i2c_addr address of slave controller
 * \param buf pointer to message content
 * \param sz size of \p buf
 */
void pb_i2c_send(i2c_addr_t i2c_addr, const uint8_t * buf, size_t sz);

/**
 * \brief global state read hook
 * \ingroup hook
 * \return current value of global state enum
 */
pb_global_state_t pb_hook_mod_state_read();
/**
 * \brief global state write hook
 * \ingroup hook
 * \param state new value of global state enum
 */
void pb_hook_mod_state_write(pb_global_state_t state);

/**
 * \brief platform-specific blocking delay function
 *
 * FIXME: this should be removed (see handover: RP2040 I2C limitations)
 */
void pb_mod_blocking_delay_ms(unsigned long ms);

#ifdef __cplusplus
}
#endif