hx711-pico-c
hx711_multi_reader.pio.h
Go to the documentation of this file.
1 // -------------------------------------------------- //
2 // This file is autogenerated by pioasm; do not edit! //
3 // -------------------------------------------------- //
4 
5 #pragma once
6 
7 #if !PICO_NO_HARDWARE
8 #include "hardware/pio.h"
9 #endif
10 
11 // ------------------ //
12 // hx711_multi_reader //
13 // ------------------ //
14 
15 #define hx711_multi_reader_wrap_target 3
16 #define hx711_multi_reader_wrap 18
17 
18 #define hx711_multi_reader_HZ 10000000
19 
20 #define hx711_multi_reader_offset_bitloop_in_pins_bit_count 9u
21 
22 static const uint16_t hx711_multi_reader_program_instructions[] = {
23  0xe020, // 0: set x, 0
24  0x8080, // 1: pull noblock
25  0x6020, // 2: out x, 32
26  // .wrap_target
27  0xe057, // 3: set y, 23
28  0x4060, // 4: in null, 32
29  0x8000, // 5: push noblock
30  0x20c4, // 6: wait 1 irq, 4
31  0xc040, // 7: irq clear 0
32  0xe001, // 8: set pins, 1
33  0x4001, // 9: in pins, 1
34  0x8000, // 10: push noblock
35  0x1088, // 11: jmp y--, 8 side 0
36  0xc000, // 12: irq nowait 0
37  0x9880, // 13: pull noblock side 1
38  0x6020, // 14: out x, 32
39  0x1023, // 15: jmp !x, 3 side 0
40  0xa041, // 16: mov y, x
41  0xe101, // 17: set pins, 1 [1]
42  0x1191, // 18: jmp y--, 17 side 0 [1]
43  // .wrap
44 };
45 
46 #if !PICO_NO_HARDWARE
47 static const struct pio_program hx711_multi_reader_program = {
49  .length = 19,
50  .origin = -1,
51 };
52 
53 static inline pio_sm_config hx711_multi_reader_program_get_default_config(uint offset) {
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 }
59 
60 // MIT License
61 //
62 // Copyright (c) 2023 Daniel Robertson
63 //
64 // Permission is hereby granted, free of charge, to any person obtaining a copy
65 // of this software and associated documentation files (the "Software"), to deal
66 // in the Software without restriction, including without limitation the rights
67 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
68 // copies of the Software, and to permit persons to whom the Software is
69 // furnished to do so, subject to the following conditions:
70 //
71 // The above copyright notice and this permission notice shall be included in all
72 // copies or substantial portions of the Software.
73 //
74 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
75 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
76 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
77 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
78 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
79 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
80 // SOFTWARE.
81 #include <assert.h>
82 #include <stddef.h>
83 #include "hardware/clocks.h"
84 #include "hardware/pio.h"
85 #include "hardware/pio_instructions.h"
86 #include "hardware/structs/clocks.h"
87 #include "hx711_multi.h"
88 #include "util.h"
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 }
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 }
179 
180 #endif
181 
#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
#define hx711_multi_reader_wrap_target
#define hx711_multi_reader_offset_bitloop_in_pins_bit_count
#define hx711_multi_reader_wrap
void hx711_multi_reader_program_init(hx711_multi_t *const hxm)
static const struct pio_program hx711_multi_reader_program
static pio_sm_config hx711_multi_reader_program_get_default_config(uint offset)
void hx711_multi_pio_init(hx711_multi_t *const hxm)
static const uint16_t hx711_multi_reader_program_instructions[]
#define hx711_multi_reader_HZ
uint _data_pin_base
Definition: hx711_multi.h:95
uint _reader_offset
Definition: hx711_multi.h:108
pio_sm_config _reader_default_config
Definition: hx711_multi.h:106
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