23 #ifndef HX711_H_0ED0E077_8980_484C_BB94_AF52973CDC09
24 #define HX711_H_0ED0E077_8980_484C_BB94_AF52973CDC09
28 #include "hardware/pio.h"
29 #include "pico/mutex.h"
35 #ifndef HX711_NO_MUTEX
36 #define HX711_MUTEX_BLOCK(mut, ...) \
38 mutex_enter_blocking(&mut); \
43 #define HX711_MUTEX_BLOCK(mut, ...) \
49 #define HX711_READ_BITS UINT8_C(24)
50 #define HX711_POWER_DOWN_TIMEOUT UINT8_C(60)
52 #define HX711_MIN_VALUE INT32_C(-0x800000)
53 #define HX711_MAX_VALUE INT32_C(0x7fffff)
55 #define HX711_PIO_MIN_GAIN UINT8_C(0)
56 #define HX711_PIO_MAX_GAIN UINT8_C(2)
84 #ifndef HX711_NO_MUTEX
335 uint32_t*
const val);
void hx711_power_down(hx711_t *const hx)
void hx711_power_up(hx711_t *const hx, const hx711_gain_t gain)
void hx711_set_gain(hx711_t *const hx, const hx711_gain_t gain)
Sets the HX711 gain.
bool hx711_is_max_saturated(const int32_t val)
Returns true if the HX711 is saturated at its maximum level.
bool hx711_get_value_noblock(hx711_t *const hx, int32_t *const val)
Obtains a value from the HX711. Returns immediately if no value is available.
void hx711_init(hx711_t *const hx, const hx711_config_t *const config)
int32_t hx711_get_value(hx711_t *const hx)
Obtains a value from the HX711. Blocks until a value is available.
void hx711_close(hx711_t *const hx)
Stop communication with the HX711.
unsigned short hx711_get_settling_time(const hx711_rate_t rate)
Returns the number of milliseconds to wait according to the given HX711 sample rate to allow readings...
bool hx711_is_min_saturated(const int32_t val)
Returns true if the HX711 is saturated at its minimum level.
static bool hx711__is_state_machine_enabled(hx711_t *const hx)
Check whether the hx struct's state machines are running.
bool hx711_is_rate_valid(const hx711_rate_t r)
Check whether the given rate is within the range of the predefined rates.
bool hx711_is_gain_valid(const hx711_gain_t g)
Check whether the given gain is within the range of the predefined gains.
static bool hx711__is_initd(hx711_t *const hx)
Check whether the hx struct has been initalised.
unsigned char hx711_get_rate_sps(const hx711_rate_t rate)
Returns the numeric sample rate of the given rate.
const unsigned char HX711_CLOCK_PULSES[3]
void hx711_wait_settle(const hx711_rate_t rate)
Convenience function for sleeping for the appropriate amount of time according to the given sample ra...
bool hx711_is_value_valid(const int32_t v)
Check whether the given value is valid for a HX711 implementation.
void(* hx711_program_init_t)(hx711_t *const)
static bool hx711__try_get_value(PIO const pio, const uint sm, uint32_t *const val)
Attempts to obtain a value from the PIO RX FIFO if one is available.
int32_t hx711_get_twos_comp(const uint32_t raw)
Convert a raw value from the HX711 to a 32-bit signed int.
void hx711_wait_power_down()
Convenience function for sleeping for the appropriate amount of time to allow the HX711 to power down...
bool hx711_is_pio_gain_valid(const uint32_t g)
Check whether a given value is permitted to be transmitted to a PIO State Machine to set a HX711's ga...
const unsigned short HX711_SETTLING_TIMES[3]
bool hx711_get_value_timeout(hx711_t *const hx, int32_t *const val, const uint timeout)
Obtains a value from the HX711. Blocks until a value is available or the timeout is reached.
void(* hx711_pio_init_t)(hx711_t *const)
uint32_t hx711_gain_to_pio_gain(const hx711_gain_t gain)
Convert a hx711_gain_t to a numeric value appropriate for a PIO State Machine.
const unsigned char HX711_SAMPLE_RATES[2]
unsigned char hx711_get_clock_pulses(const hx711_gain_t gain)
Returns the clock pulse count for a given gain value.
hx711_pio_init_t pio_init
const pio_program_t * reader_prog
hx711_program_init_t reader_prog_init
const pio_program_t * _reader_prog
pio_sm_config _reader_prog_default_config