36#ifndef HX711_DEVICES_NB
37#define HX711_DEVICES_NB 4
44#ifndef HX711_PWM_FREQUENCY
45#define HX711_PWM_FREQUENCY 6000000
49#define HX711_DEVICES {}
52#ifndef HX711_FORCE_SENSOR_ID
53#define HX711_FORCE_SENSOR_ID ABI_BROADCAST
57#define HX711_DEBUG false
65#define HX711_PERIOD (HX711_PWM_FREQUENCY / 50000)
83static void pwmpcb(PWMDriver *pwmp __attribute__((unused)));
87 .measurement_ready =
false,
99 { PWM_OUTPUT_DISABLED, NULL },
100 { PWM_OUTPUT_DISABLED, NULL },
101 { PWM_OUTPUT_DISABLED, NULL },
102 { PWM_OUTPUT_DISABLED, NULL },
116 pwmcfg.channels[HX711_PWM_CHANNEL].mode = PWM_OUTPUT_ACTIVE_HIGH;
126 pwmStart(&HX711_PWM_DRIVER, &
pwmcfg);
128 hx711.measurement_ready =
false;
129 hx711.read_bit_idx = 0;
142 if(
hx711.measurement_ready) {
145 values[i] =
hx711.devices[i].measurement;
153 raw_val[i] = values[i];
162 char hx711_freq_str[15];
163 int hx711_len = snprintf(hx711_str,
sizeof(hx711_str),
"HX711");
164 int hx711_freq_len = snprintf(hx711_freq_str,
sizeof(hx711_freq_str),
"HX711 freq");
171 pprz_msg_send_DEBUG_VECT(&
pprzlog_tp.trans_tx, &flightrecorder_sdlog.device, AC_ID, hx711_len, hx711_str,
HX711_DEVICES_NB, raw_val);
172 pprz_msg_send_DEBUG_VECT(&
pprzlog_tp.trans_tx, &flightrecorder_sdlog.device, AC_ID, hx711_freq_len, hx711_freq_str, 1, &freq);
175 hx711.measurement_ready =
false;
187 hx711.measurement_ready =
false;
188 hx711.read_bit_idx = 0;
189 pwmEnableChannel(&HX711_PWM_DRIVER, HX711_PWM_CHANNEL,
HX711_PERIOD/2);
190 pwmEnableChannelNotification(&HX711_PWM_DRIVER, HX711_PWM_CHANNEL);
197static void pwmpcb(PWMDriver *pwmp __attribute__((unused))) {
202 pwmDisableChannelNotificationI(&HX711_PWM_DRIVER, HX711_PWM_CHANNEL);
203 pwmDisableChannelI(&HX711_PWM_DRIVER, HX711_PWM_CHANNEL);
204 chSysUnlockFromISR();
209 if(
hx711.read_bit_idx < 24) {
214 if(
hx711.read_bit_idx == 0)
215 dev->measurement = 0;
217 dev->measurement <<= 1;
221 dev->measurement |= 1;
224 if(
dev->measurement & (1 << 23)) {
225 dev->measurement |= 0xFF000000;
229 hx711.read_bit_idx++;
233 pwmDisableChannelNotificationI(&HX711_PWM_DRIVER, HX711_PWM_CHANNEL);
234 pwmDisableChannelI(&HX711_PWM_DRIVER, HX711_PWM_CHANNEL);
236 hx711.measurement_ready =
true;
237 chSysUnlockFromISR();
241 chSysUnlockFromISR();
Main include for ABI (AirBorneInterface).
void gpio_setup_pin_af(ioportid_t port, uint16_t pin, uint8_t af, bool is_output)
Setup a gpio for input or output with alternate function.
void gpio_setup_input(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as inputs.
static uint8_t gpio_get(ioportid_t port, uint16_t pin)
Get level of a gpio.
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
static void pwmpcb(PWMDriver *pwmp)
PWM callback function.
Common code for AP and FBW telemetry.
static struct uart_periph * dev
Some architecture independent helper functions for GPIOs.
static void pwmpcb(PWMDriver *pwmp)
Callback on the falling edge of the clock signal.
struct hx711_dev_t devices[HX711_DEVICES_NB]
static volatile struct hx711_t hx711
#define HX711_FORCE_SENSOR_ID
volatile uint8_t read_bit_idx
#define HX711_PWM_FREQUENCY
volatile bool measurement_ready
void hx711_event(void)
Start a measurement and publish the results when possible.
Interface for the HX711 sensor.
struct pprzlog_transport pprzlog_tp
PPRZLOG transport structure.
Architecture independent timing functions.
static float get_sys_time_float(void)
Get the time in seconds since startup.
Periodic telemetry system header (includes downlink utility and generated code).
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.