37 #if PERIODIC_TELEMETRY
44 #ifndef SOFTI2C0_DIVIDER
45 #define SOFTI2C0_DIVIDER 1
47 #ifndef SOFTI2C1_DIVIDER
48 #define SOFTI2C1_DIVIDER 1
74 #if USE_SOFTI2C0 && ( \
75 !defined(SOFTI2C0_SDA_GPIO) || !defined(SOFTI2C0_SDA_PIN) || \
76 !defined(SOFTI2C0_SCL_GPIO) || !defined(SOFTI2C0_SCL_PIN))
77 #error "SDA and SCL pins must be configured for SOFTI2C0!"
80 #if USE_SOFTI2C1 && ( \
81 !defined(SOFTI2C1_SDA_GPIO) || !defined(SOFTI2C1_SDA_PIN) || \
82 !defined(SOFTI2C1_SCL_GPIO) || !defined(SOFTI2C1_SCL_PIN))
83 #error "SDA and SCL pins must be configured for SOFTI2C1!"
90 void softi2c0_init(
void) {
94 #if PERIODIC_TELEMETRY
95 void send_softi2c0_err(
struct transport_tx *trans,
struct link_device *
dev)
97 uint16_t i2c0_wd_reset_cnt = softi2c0.errors->wd_reset_cnt;
98 uint16_t i2c0_queue_full_cnt = softi2c0.errors->queue_full_cnt;
99 uint16_t i2c0_ack_fail_cnt = softi2c0.errors->ack_fail_cnt;
100 uint16_t i2c0_miss_start_stop_cnt = softi2c0.errors->miss_start_stop_cnt;
101 uint16_t i2c0_arb_lost_cnt = softi2c0.errors->arb_lost_cnt;
102 uint16_t i2c0_over_under_cnt = softi2c0.errors->over_under_cnt;
103 uint16_t i2c0_pec_recep_cnt = softi2c0.errors->pec_recep_cnt;
104 uint16_t i2c0_timeout_tlow_cnt = softi2c0.errors->timeout_tlow_cnt;
105 uint16_t i2c0_smbus_alert_cnt = softi2c0.errors->smbus_alert_cnt;
106 uint16_t i2c0_unexpected_event_cnt = softi2c0.errors->unexpected_event_cnt;
107 uint32_t i2c0_last_unexpected_event = softi2c0.errors->last_unexpected_event;
109 pprz_msg_send_I2C_ERRORS(trans,
dev, AC_ID,
111 &i2c0_queue_full_cnt,
113 &i2c0_miss_start_stop_cnt,
115 &i2c0_over_under_cnt,
117 &i2c0_timeout_tlow_cnt,
118 &i2c0_smbus_alert_cnt,
119 &i2c0_unexpected_event_cnt,
120 &i2c0_last_unexpected_event,
129 void softi2c1_init(
void) {
133 #if PERIODIC_TELEMETRY
134 void send_softi2c1_err(
struct transport_tx *trans,
struct link_device *
dev)
136 uint16_t i2c1_wd_reset_cnt = softi2c1.errors->wd_reset_cnt;
137 uint16_t i2c1_queue_full_cnt = softi2c1.errors->queue_full_cnt;
138 uint16_t i2c1_ack_fail_cnt = softi2c1.errors->ack_fail_cnt;
139 uint16_t i2c1_miss_start_stop_cnt = softi2c1.errors->miss_start_stop_cnt;
140 uint16_t i2c1_arb_lost_cnt = softi2c1.errors->arb_lost_cnt;
141 uint16_t i2c1_over_under_cnt = softi2c1.errors->over_under_cnt;
142 uint16_t i2c1_pec_recep_cnt = softi2c1.errors->pec_recep_cnt;
143 uint16_t i2c1_timeout_tlow_cnt = softi2c1.errors->timeout_tlow_cnt;
144 uint16_t i2c1_smbus_alert_cnt = softi2c1.errors->smbus_alert_cnt;
145 uint16_t i2c1_unexpected_event_cnt = softi2c1.errors->unexpected_event_cnt;
146 uint32_t i2c1_last_unexpected_event = softi2c1.errors->last_unexpected_event;
148 pprz_msg_send_I2C_ERRORS(trans,
dev, AC_ID,
150 &i2c1_queue_full_cnt,
152 &i2c1_miss_start_stop_cnt,
154 &i2c1_over_under_cnt,
156 &i2c1_timeout_tlow_cnt,
157 &i2c1_smbus_alert_cnt,
158 &i2c1_unexpected_event_cnt,
159 &i2c1_last_unexpected_event,
167 #if defined(CHIBIOS_MCU_ARCH_H) || defined(STM32_MCU_ARCH_H)
197 #ifdef STM32_MCU_ARCH_H
209 void softi2c0_hw_init(
void) {
214 softi2c0.reg_addr = (
void *) &softi2c0_device;
215 softi2c0.errors = &softi2c0_errors;
218 softi2c0_device.periph = &softi2c0;
219 softi2c0_device.sda_port = SOFTI2C0_SDA_GPIO;
220 softi2c0_device.sda_pin = SOFTI2C0_SDA_PIN;
221 softi2c0_device.scl_port = SOFTI2C0_SCL_GPIO;
222 softi2c0_device.scl_pin = SOFTI2C0_SCL_PIN;
226 SOFTI2C0_SDA_GPIO, SOFTI2C0_SDA_PIN,
227 SOFTI2C0_SCL_GPIO, SOFTI2C0_SCL_PIN);
234 void softi2c1_hw_init(
void) {
239 softi2c1.reg_addr = (
void *) &softi2c1_device;
240 softi2c1.errors = &softi2c1_errors;
243 softi2c1_device.periph = &softi2c1;
244 softi2c1_device.sda_port = SOFTI2C1_SDA_GPIO;
245 softi2c1_device.sda_pin = SOFTI2C1_SDA_PIN;
246 softi2c1_device.scl_port = SOFTI2C1_SCL_GPIO;
247 softi2c1_device.scl_pin = SOFTI2C1_SCL_PIN;
251 SOFTI2C1_SDA_GPIO, SOFTI2C1_SDA_PIN,
252 SOFTI2C1_SCL_GPIO, SOFTI2C1_SCL_PIN);
320 default:
return false;
345 default:
return false;
376 default:
return false;
407 default:
return false;
440 default:
return false;
474 default:
return false;
481 #pragma GCC diagnostic push
482 #pragma GCC diagnostic ignored "-Wcast-qual"
603 #pragma GCC diagnostic pop
610 if (
p->trans_insert_idx !=
p->trans_extract_idx) {
626 static int softi2c0_cnt = 1;
635 static int softi2c1_cnt = 1;
651 return (
p->status ==
I2CIdle) && (
p->trans_insert_idx ==
p->trans_extract_idx);
656 if (next_idx ==
p->trans_extract_idx) {
658 p->errors->queue_full_cnt++;
664 p->trans[
p->trans_insert_idx] = t;
665 p->trans_insert_idx = next_idx;