hx711-pico-c
hx711_multi_reader.pio.h File Reference
#include "hardware/pio.h"
#include <assert.h>
#include <stddef.h>
#include "hardware/clocks.h"
#include "hardware/pio_instructions.h"
#include "hardware/structs/clocks.h"
#include "hx711_multi.h"
#include "util.h"

Go to the source code of this file.

Macros

#define hx711_multi_reader_wrap_target   3
 
#define hx711_multi_reader_wrap   18
 
#define hx711_multi_reader_HZ   10000000
 
#define hx711_multi_reader_offset_bitloop_in_pins_bit_count   9u
 

Functions

static pio_sm_config hx711_multi_reader_program_get_default_config (uint offset)
 
void hx711_multi_pio_init (hx711_multi_t *const hxm)
 
void hx711_multi_reader_program_init (hx711_multi_t *const hxm)
 

Variables

static const uint16_t hx711_multi_reader_program_instructions []
 
static const struct pio_program hx711_multi_reader_program
 

Macro Definition Documentation

◆ hx711_multi_reader_HZ

#define hx711_multi_reader_HZ   10000000

Definition at line 18 of file hx711_multi_reader.pio.h.

◆ hx711_multi_reader_offset_bitloop_in_pins_bit_count

#define hx711_multi_reader_offset_bitloop_in_pins_bit_count   9u

Definition at line 20 of file hx711_multi_reader.pio.h.

◆ hx711_multi_reader_wrap

#define hx711_multi_reader_wrap   18

Definition at line 16 of file hx711_multi_reader.pio.h.

◆ hx711_multi_reader_wrap_target

#define hx711_multi_reader_wrap_target   3

Definition at line 15 of file hx711_multi_reader.pio.h.

Function Documentation

◆ hx711_multi_pio_init()

void hx711_multi_pio_init ( hx711_multi_t *const  hxm)

Definition at line 89 of file hx711_multi_reader.pio.h.

89  {
90  assert(hxm != NULL);
91  assert(hxm->_pio != NULL);
92  assert(hxm->_chips_len > 0);
93  pio_gpio_init(
94  hxm->_pio,
95  hxm->_clock_pin);
97  hxm->_pio,
98  hxm->_data_pin_base,
99  hxm->_chips_len);
100  // make sure conversion done is valid and routable
103  pio_interrupt_clear(
104  hxm->_pio,
106  // make sure data ready is valid and not routable
107  // although this is not strictly necessary
112  pio_interrupt_clear(
113  hxm->_pio,
115 }
#define HX711_MULTI_CONVERSION_DONE_IRQ_NUM
PIO interrupt number which is set by the reader PIO State Machine when a conversion period ends....
Definition: hx711_multi.h:43
#define HX711_MULTI_DATA_READY_IRQ_NUM
PIO interrupt number which is used between the awaiter and reader PIO State Machines to indicate when...
Definition: hx711_multi.h:52
uint _data_pin_base
Definition: hx711_multi.h:95
size_t _chips_len
Definition: hx711_multi.h:96
bool util_routable_pio_interrupt_num_is_valid(const uint pio_interrupt_num)
Check whether a PIO interrupt number is a valid routable interrupt number.
Definition: util.c:382
void util_pio_gpio_contiguous_init(PIO const pio, const uint base, const uint len)
Inits GPIO pins for PIO from base to base + len.
Definition: util.c:317
bool util_pio_interrupt_num_is_valid(const uint pio_interrupt_num)
Check whether a PIO interrupt number is valid.
Definition: util.c:374

References hx711_multi_t::_chips_len, hx711_multi_t::_clock_pin, hx711_multi_t::_data_pin_base, hx711_multi_t::_pio, HX711_MULTI_CONVERSION_DONE_IRQ_NUM, HX711_MULTI_DATA_READY_IRQ_NUM, util_pio_gpio_contiguous_init(), util_pio_interrupt_num_is_valid(), and util_routable_pio_interrupt_num_is_valid().

◆ hx711_multi_reader_program_get_default_config()

static pio_sm_config hx711_multi_reader_program_get_default_config ( uint  offset)
inlinestatic

Definition at line 53 of file hx711_multi_reader.pio.h.

53  {
54  pio_sm_config c = pio_get_default_sm_config();
55  sm_config_set_wrap(&c, offset + hx711_multi_reader_wrap_target, offset + hx711_multi_reader_wrap);
56  sm_config_set_sideset(&c, 2, true, false);
57  return c;
58 }
#define hx711_multi_reader_wrap_target
#define hx711_multi_reader_wrap

References hx711_multi_reader_wrap, and hx711_multi_reader_wrap_target.

Referenced by hx711_multi_reader_program_init().

◆ hx711_multi_reader_program_init()

void hx711_multi_reader_program_init ( hx711_multi_t *const  hxm)

Definition at line 116 of file hx711_multi_reader.pio.h.

116  {
117  assert(hxm != NULL);
118  assert(hxm->_pio != NULL);
120  pio_encode_in(pio_pins, hxm->_chips_len);
122  hxm->_reader_offset);
123  const float div = (float)(clock_get_hz(clk_sys)) / (uint)hx711_multi_reader_HZ;
124  sm_config_set_clkdiv(
125  &cfg,
126  div);
127  //clock pin setup
128  pio_sm_set_out_pins(
129  hxm->_pio,
130  hxm->_reader_sm,
131  hxm->_clock_pin,
132  1);
133  pio_sm_set_set_pins(
134  hxm->_pio,
135  hxm->_reader_sm,
136  hxm->_clock_pin,
137  1);
138  pio_sm_set_consecutive_pindirs(
139  hxm->_pio,
140  hxm->_reader_sm,
141  hxm->_clock_pin,
142  1,
143  true);
144  sm_config_set_set_pins(
145  &cfg,
146  hxm->_clock_pin,
147  1);
148  sm_config_set_out_pins(
149  &cfg,
150  hxm->_clock_pin,
151  1);
152  sm_config_set_sideset_pins(
153  &cfg,
154  hxm->_clock_pin);
155  //data pins
156  pio_sm_set_in_pins(
157  hxm->_pio,
158  hxm->_reader_sm,
159  hxm->_data_pin_base);
160  pio_sm_set_consecutive_pindirs(
161  hxm->_pio,
162  hxm->_reader_sm,
163  hxm->_data_pin_base,
164  hxm->_chips_len,
165  false); //false = input
166  sm_config_set_in_pins(
167  &cfg,
168  hxm->_data_pin_base);
169  sm_config_set_in_shift(
170  &cfg,
171  false, //false = shift in left
172  false, //false = autopush disabled
173  hxm->_chips_len);
174  pio_sm_clear_fifos(
175  hxm->_pio,
176  hxm->_reader_sm);
177  hxm->_reader_default_config = cfg;
178 }
#define hx711_multi_reader_offset_bitloop_in_pins_bit_count
static pio_sm_config hx711_multi_reader_program_get_default_config(uint offset)
#define hx711_multi_reader_HZ
uint _reader_offset
Definition: hx711_multi.h:108
pio_sm_config _reader_default_config
Definition: hx711_multi.h:106

References hx711_multi_t::_chips_len, hx711_multi_t::_clock_pin, hx711_multi_t::_data_pin_base, hx711_multi_t::_pio, hx711_multi_t::_reader_default_config, hx711_multi_t::_reader_offset, hx711_multi_t::_reader_sm, hx711_multi_reader_HZ, hx711_multi_reader_offset_bitloop_in_pins_bit_count, and hx711_multi_reader_program_get_default_config().

Variable Documentation

◆ hx711_multi_reader_program

const struct pio_program hx711_multi_reader_program
static
Initial value:
= {
.length = 19,
.origin = -1,
}
static const uint16_t hx711_multi_reader_program_instructions[]

Definition at line 22 of file hx711_multi_reader.pio.h.

◆ hx711_multi_reader_program_instructions

const uint16_t hx711_multi_reader_program_instructions[]
static
Initial value:
= {
0xe020,
0x8080,
0x6020,
0xe057,
0x4060,
0x8000,
0x20c4,
0xc040,
0xe001,
0x4001,
0x8000,
0x1088,
0xc000,
0x9880,
0x6020,
0x1023,
0xa041,
0xe101,
0x1191,
}

Definition at line 22 of file hx711_multi_reader.pio.h.