hx711-pico-c
|
#include <stdint.h>
#include "hardware/pio.h"
#include "hardware/platform_defs.h"
#include "hardware/sync.h"
#include "pico/mutex.h"
#include "pico/types.h"
Go to the source code of this file.
Macros | |
#define | UTIL_NUM_DMA_IRQS UINT8_C(2) |
#define | UTIL_DMA_IRQ_INDEX_MIN UINT8_C(0) |
#define | UTIL_DMA_IRQ_INDEX_MAX UINT8_C(UTIL_NUM_DMA_IRQS - 1) |
#define | UTIL_PIO_IRQ_INDEX_MIN UINT8_C(0) |
#define | UTIL_PIO_IRQ_INDEX_MAX UINT8_C(NUM_PIOS - 1) |
#define | UTIL_PIO_INTERRUPT_NUM_MIN UINT8_C(0) |
#define | UTIL_PIO_INTERRUPT_NUM_MAX UINT8_C(7) |
#define | UTIL_ROUTABLE_PIO_INTERRUPT_NUM_MIN UINT8_C(0) |
#define | UTIL_ROUTABLE_PIO_INTERRUPT_NUM_MAX UINT8_C(3) |
#define | UTIL_MUTEX_BLOCK(mut, ...) |
#define | UTIL_INTERRUPTS_OFF_BLOCK(...) |
#define | UTIL_DECL_IN_RANGE_FUNC(TYPE) |
Functions | |
bool | util_dma_irq_index_is_valid (const uint idx) |
Check whether a DMA IRQ index is valid. More... | |
uint | util_dma_get_irq_from_index (const uint idx) |
Gets the NVIC DMA IRQ number using the DMA IRQ index. More... | |
int | util_dma_get_index_from_irq (const uint irq_num) |
Gets the DMA IRQ index using the NVIC IRQ number. More... | |
void | util_dma_set_exclusive_channel_irq_handler (const uint irq_index, const uint channel, const irq_handler_t handler, const bool enabled) |
Set and enable an exclusive handler for a DMA channel. More... | |
uint32_t | util_dma_get_transfer_count (const uint channel) |
Get the transfer count for a given DMA channel. When a DMA transfer is active, this count is the number of transfers remaining. More... | |
bool | util_dma_channel_wait_for_finish_timeout (const uint channel, const absolute_time_t *const end) |
Wait until channel has completed transferring up to a timeout. More... | |
uint | util_dma_get_irqn (const uint irq_index) |
Gets the NVIC IRQ number based on the DMA IRQ index. More... | |
void | util_dma_channel_set_quiet (const uint channel, const bool quiet) |
Sets a DMA channel's IRQ quiet mode. More... | |
void | util_gpio_set_contiguous_input_pins (const uint base, const uint len) |
Sets GPIO pins from base to base + len to input. More... | |
void | util_gpio_set_output (const uint gpio) |
Initialises and sets GPIO pin to output. More... | |
void | util_irq_set_exclusive_pio_interrupt_num_handler (PIO const pio, const uint irq_index, const uint pio_interrupt_num, const irq_handler_t handler, const bool enabled) |
Set and enable an exclusive interrupt handler for a given pio_interrupt_num. More... | |
bool | util_pio_irq_index_is_valid (const uint idx) |
Check whether PIO IRQ index is valid. More... | |
uint | util_pio_get_irq_from_index (PIO const pio, const uint idx) |
Gets the NVIC PIO IRQ number using a PIO pointer and PIO IRQ index. More... | |
int | util_pio_get_index_from_irq (const uint irq_num) |
Gets the PIO IRQ index using the NVIC IRQ number. More... | |
PIO const | util_pio_get_pio_from_irq (const uint irq_num) |
Gets the PIO using the NVIC IRQ number. More... | |
uint | util_pion_get_irqn (PIO const pio, const uint irq_index) |
uint | util_pio_get_pis_from_pio_interrupt_num (const uint pio_interrupt_num) |
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. More... | |
void | util_pio_sm_clear_rx_fifo (PIO const pio, const uint sm) |
Clears a given state machine's RX FIFO. More... | |
void | util_pio_sm_clear_osr (PIO const pio, const uint sm) |
Clears a given state machine's OSR. More... | |
void | util_pio_sm_clear_isr (PIO const pio, const uint sm) |
Clears a given state machine's ISR. More... | |
bool | util_pio_sm_is_enabled (PIO const pio, const uint sm) |
Check whether a given state machine is enabled. More... | |
bool | util_pio_interrupt_num_is_valid (const uint pio_interrupt_num) |
Check whether a PIO interrupt number is valid. More... | |
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. More... | |
void | util_pio_interrupt_wait (PIO const pio, const uint pio_interrupt_num) |
Waits for a given PIO interrupt to be set. More... | |
void | util_pio_interrupt_wait_cleared (PIO const pio, const uint pio_interrupt_num) |
Waits until a given PIO interrupt is cleared. More... | |
bool | util_pio_interrupt_wait_cleared_timeout (PIO const pio, const uint pio_interrupt_num, const absolute_time_t *const end) |
Waits until the given interrupt is cleared, up to a maximum timeout. More... | |
void | util_pio_interrupt_wait_clear (PIO const pio, const uint pio_interrupt_num) |
Waits for a given PIO interrupt to be set and then clears it. More... | |
bool | util_pio_interrupt_wait_timeout (PIO const pio, const uint pio_interrupt_num, const absolute_time_t *const end) |
Waits for a given PIO to be set within the timeout period. More... | |
bool | util_pio_interrupt_wait_clear_timeout (PIO const pio, const uint pio_interrupt_num, const absolute_time_t *const end) |
Waits for a given PIO to be set within the timeout period and then clears it. More... | |
bool | util_pio_sm_try_get (PIO const pio, const uint sm, uint32_t *const word, const uint threshold) |
Attempts to get a word from the state machine's RX FIFO if more than threshold words are in the buffer. More... | |
Variables | |
const uint8_t | util_pio_to_irq_map [NUM_PIOS *2] |
Quick lookup for finding an NVIC IRQ number for a PIO and interrupt index number. More... | |
const uint8_t | util_dma_to_irq_map [UTIL_NUM_DMA_IRQS] |
Quick lookup for finding an NVIC IRQ number for a DMA interrupt index number. More... | |
#define UTIL_DECL_IN_RANGE_FUNC | ( | TYPE | ) |
#define UTIL_DMA_IRQ_INDEX_MAX UINT8_C(UTIL_NUM_DMA_IRQS - 1) |
#define UTIL_INTERRUPTS_OFF_BLOCK | ( | ... | ) |
#define UTIL_MUTEX_BLOCK | ( | mut, | |
... | |||
) |
void util_dma_channel_set_quiet | ( | const uint | channel, |
const bool | quiet | ||
) |
Sets a DMA channel's IRQ quiet mode.
channel | |
quiet | true for quiet otherwise false |
Definition at line 161 of file util.c.
Referenced by hx711_multi_close().
bool util_dma_channel_wait_for_finish_timeout | ( | const uint | channel, |
const absolute_time_t *const | end | ||
) |
Wait until channel has completed transferring up to a timeout.
channel | |
end |
int util_dma_get_index_from_irq | ( | const uint | irq_num | ) |
Gets the DMA IRQ index using the NVIC IRQ number.
irq_num |
Definition at line 78 of file util.c.
References util_dma_to_irq_map.
uint util_dma_get_irq_from_index | ( | const uint | idx | ) |
Gets the NVIC DMA IRQ number using the DMA IRQ index.
idx |
Definition at line 72 of file util.c.
References util_dma_irq_index_is_valid(), and util_dma_to_irq_map.
uint util_dma_get_irqn | ( | const uint | irq_index | ) |
Gets the NVIC IRQ number based on the DMA IRQ index.
irq_index | 0 or 1 |
Definition at line 144 of file util.c.
References UTIL_DMA_IRQ_INDEX_MAX, UTIL_DMA_IRQ_INDEX_MIN, and util_dma_to_irq_map.
Referenced by hx711_multi__async_dma_irq_handler(), hx711_multi__init_irq(), hx711_multi__is_initd(), hx711_multi_close(), and util_dma_set_exclusive_channel_irq_handler().
uint32_t util_dma_get_transfer_count | ( | const uint | channel | ) |
Get the transfer count for a given DMA channel. When a DMA transfer is active, this count is the number of transfers remaining.
channel |
bool util_dma_irq_index_is_valid | ( | const uint | idx | ) |
Check whether a DMA IRQ index is valid.
idx |
Definition at line 65 of file util.c.
References UTIL_DMA_IRQ_INDEX_MAX, and UTIL_DMA_IRQ_INDEX_MIN.
Referenced by hx711_multi__init_asert(), util_dma_get_irq_from_index(), and util_dma_set_exclusive_channel_irq_handler().
void util_dma_set_exclusive_channel_irq_handler | ( | const uint | irq_index, |
const uint | channel, | ||
const irq_handler_t | handler, | ||
const bool | enabled | ||
) |
Set and enable an exclusive handler for a DMA channel.
irq_index | |
channel | |
handler | |
enabled |
Definition at line 94 of file util.c.
References util_dma_get_irqn(), and util_dma_irq_index_is_valid().
void util_gpio_set_contiguous_input_pins | ( | const uint | base, |
const uint | len | ||
) |
Sets GPIO pins from base to base + len to input.
base | |
len |
Definition at line 170 of file util.c.
Referenced by hx711_multi_init().
void util_gpio_set_output | ( | const uint | gpio | ) |
Initialises and sets GPIO pin to output.
gpio |
Definition at line 185 of file util.c.
Referenced by hx711_init(), and hx711_multi_init().
void util_irq_set_exclusive_pio_interrupt_num_handler | ( | PIO const | pio, |
const uint | irq_index, | ||
const uint | pio_interrupt_num, | ||
const irq_handler_t | handler, | ||
const bool | enabled | ||
) |
Set and enable an exclusive interrupt handler for a given pio_interrupt_num.
pio | |
irq_index | |
pio_interrupt_num | |
handler | |
enabled |
Definition at line 191 of file util.c.
References util_pio_get_irq_from_index(), util_pio_get_pis_from_pio_interrupt_num(), util_pio_irq_index_is_valid(), and util_routable_pio_interrupt_num_is_valid().
int util_pio_get_index_from_irq | ( | const uint | irq_num | ) |
Gets the PIO IRQ index using the NVIC IRQ number.
irq_num |
uint util_pio_get_irq_from_index | ( | PIO const | pio, |
const uint | idx | ||
) |
Gets the NVIC PIO IRQ number using a PIO pointer and PIO IRQ index.
idx |
Definition at line 250 of file util.c.
References util_pio_irq_index_is_valid(), and util_pio_to_irq_map.
Referenced by hx711_multi__async_pio_irq_handler(), hx711_multi__init_irq(), hx711_multi__is_initd(), hx711_multi_async_start(), hx711_multi_close(), and util_irq_set_exclusive_pio_interrupt_num_handler().
PIO const util_pio_get_pio_from_irq | ( | const uint | irq_num | ) |
Gets the PIO using the NVIC IRQ number.
irq_num |
uint util_pio_get_pis_from_pio_interrupt_num | ( | const uint | pio_interrupt_num | ) |
Definition at line 301 of file util.c.
References util_routable_pio_interrupt_num_is_valid().
Referenced by hx711_multi__async_finish(), hx711_multi__async_pio_irq_handler(), hx711_multi__init_irq(), hx711_multi_close(), and util_irq_set_exclusive_pio_interrupt_num_handler().
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.
pio | |
base | |
len |
Definition at line 317 of file util.c.
Referenced by hx711_multi_pio_init().
bool util_pio_interrupt_num_is_valid | ( | const uint | pio_interrupt_num | ) |
Check whether a PIO interrupt number is valid.
pio_interrupt_num |
Definition at line 374 of file util.c.
References UTIL_PIO_INTERRUPT_NUM_MAX, and UTIL_PIO_INTERRUPT_NUM_MIN.
Referenced by hx711_multi_pio_init(), util_pio_interrupt_wait(), util_pio_interrupt_wait_clear(), util_pio_interrupt_wait_clear_timeout(), util_pio_interrupt_wait_cleared(), util_pio_interrupt_wait_cleared_timeout(), and util_pio_interrupt_wait_timeout().
void util_pio_interrupt_wait | ( | PIO const | pio, |
const uint | pio_interrupt_num | ||
) |
Waits for a given PIO interrupt to be set.
pio | |
pio_interrupt_num |
Definition at line 390 of file util.c.
References util_pio_interrupt_num_is_valid().
Referenced by util_pio_interrupt_wait_clear().
void util_pio_interrupt_wait_clear | ( | PIO const | pio, |
const uint | pio_interrupt_num | ||
) |
Waits for a given PIO interrupt to be set and then clears it.
pio | |
pio_interrupt_num |
Definition at line 430 of file util.c.
References util_pio_interrupt_num_is_valid(), and util_pio_interrupt_wait().
bool util_pio_interrupt_wait_clear_timeout | ( | PIO const | pio, |
const uint | pio_interrupt_num, | ||
const absolute_time_t *const | end | ||
) |
Waits for a given PIO to be set within the timeout period and then clears it.
pio | |
pio_interrupt_num | |
end |
Definition at line 459 of file util.c.
References util_pio_interrupt_num_is_valid(), and util_pio_interrupt_wait_timeout().
void util_pio_interrupt_wait_cleared | ( | PIO const | pio, |
const uint | pio_interrupt_num | ||
) |
Waits until a given PIO interrupt is cleared.
pio | |
pio_interrupt_num |
Definition at line 400 of file util.c.
References util_pio_interrupt_num_is_valid().
bool util_pio_interrupt_wait_cleared_timeout | ( | PIO const | pio, |
const uint | pio_interrupt_num, | ||
const absolute_time_t *const | end | ||
) |
Waits until the given interrupt is cleared, up to a maximum timeout.
pio | |
pio_interrupt_num | |
end |
Definition at line 410 of file util.c.
References util_pio_interrupt_num_is_valid().
bool util_pio_interrupt_wait_timeout | ( | PIO const | pio, |
const uint | pio_interrupt_num, | ||
const absolute_time_t *const | end | ||
) |
Waits for a given PIO to be set within the timeout period.
pio | |
pio_interrupt_num | |
end |
Definition at line 439 of file util.c.
References util_pio_interrupt_num_is_valid().
Referenced by util_pio_interrupt_wait_clear_timeout().
bool util_pio_irq_index_is_valid | ( | const uint | idx | ) |
Check whether PIO IRQ index is valid.
idx |
Definition at line 226 of file util.c.
References UTIL_PIO_IRQ_INDEX_MAX, and UTIL_PIO_IRQ_INDEX_MIN.
Referenced by hx711_multi__init_asert(), util_irq_set_exclusive_pio_interrupt_num_handler(), util_pio_get_irq_from_index(), and util_pion_get_irqn().
void util_pio_sm_clear_isr | ( | PIO const | pio, |
const uint | sm | ||
) |
void util_pio_sm_clear_osr | ( | PIO const | pio, |
const uint | sm | ||
) |
void util_pio_sm_clear_rx_fifo | ( | PIO const | pio, |
const uint | sm | ||
) |
Clears a given state machine's RX FIFO.
pio | |
sm |
Definition at line 334 of file util.c.
Referenced by hx711_multi__async_start_dma().
bool util_pio_sm_is_enabled | ( | PIO const | pio, |
const uint | sm | ||
) |
Check whether a given state machine is enabled.
pio | |
sm |
Definition at line 366 of file util.c.
Referenced by hx711__is_state_machine_enabled(), hx711__try_get_value(), and hx711_multi__is_state_machines_enabled().
bool util_pio_sm_try_get | ( | PIO const | pio, |
const uint | sm, | ||
uint32_t *const | word, | ||
const uint | threshold | ||
) |
Attempts to get a word from the state machine's RX FIFO if more than threshold words are in the buffer.
pio | |
sm | |
word | variable to be set |
threshold | word count (1 word = 8 bytes) |
Definition at line 484 of file util.c.
Referenced by hx711__try_get_value().
uint util_pion_get_irqn | ( | PIO const | pio, |
const uint | irq_index | ||
) |
Definition at line 233 of file util.c.
References util_pio_irq_index_is_valid(), and util_pio_to_irq_map.
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.
pio_interrupt_num |
Definition at line 382 of file util.c.
References UTIL_ROUTABLE_PIO_INTERRUPT_NUM_MAX, and UTIL_ROUTABLE_PIO_INTERRUPT_NUM_MIN.
Referenced by hx711_multi_pio_init(), util_irq_set_exclusive_pio_interrupt_num_handler(), and util_pio_get_pis_from_pio_interrupt_num().
|
extern |
Quick lookup for finding an NVIC IRQ number for a DMA interrupt index number.
Definition at line 55 of file util.c.
Referenced by util_dma_get_index_from_irq(), util_dma_get_irq_from_index(), and util_dma_get_irqn().
|
extern |
Quick lookup for finding an NVIC IRQ number for a PIO and interrupt index number.
Definition at line 48 of file util.c.
Referenced by util_pio_get_irq_from_index(), and util_pion_get_irqn().