Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gpio_get_out_level() accessor, and correct SIO GPIO_OUT struct ty… #247

Merged
merged 2 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/rp2040/hardware_structs/include/hardware/structs/sio.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ typedef struct {
io_ro_32 gpio_hi_in;
uint32_t _pad;

io_wo_32 gpio_out;
io_rw_32 gpio_out;
io_wo_32 gpio_set;
io_wo_32 gpio_clr;
io_wo_32 gpio_togl;
Expand All @@ -27,7 +27,7 @@ typedef struct {
io_wo_32 gpio_oe_clr;
io_wo_32 gpio_oe_togl;

io_wo_32 gpio_hi_out;
io_rw_32 gpio_hi_out;
io_wo_32 gpio_hi_set;
io_wo_32 gpio_hi_clr;
io_wo_32 gpio_hi_togl;
Expand Down
20 changes: 20 additions & 0 deletions src/rp2_common/hardware_gpio/include/hardware/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,26 @@ static inline void gpio_put(uint gpio, bool value) {
gpio_clr_mask(mask);
}

/*! \brief Determine whether a GPIO is currently driven high or low
* \ingroup hardware_gpio
*
* This function returns the high/low output level most recently assigned to a
* GPIO via gpio_put() or similar. This is the value that is presented outward
* to the IO muxing, *not* the input level back from the pad (which can be
* read using gpio_get()).
*
* To avoid races, this function must not be used for read-modify-write
* sequences when driving GPIOs -- instead functions like gpio_put() should be
* used to atomically update GPIOs. This accessor is intended for debug use
* only.
*
* \param gpio GPIO number
* \return true if the GPIO output level is high, false if low.
*/
static inline bool gpio_get_out_level(uint gpio) {
return !!(sio_hw->gpio_out & (1u << gpio));
}

// ----------------------------------------------------------------------------
// Direction
// ----------------------------------------------------------------------------
Expand Down