The public API for GPIO flags should use unsigned values, and for
MISRA compliance the size should not be platform-dependent. Add a
typedef for generic flags.
Also add typedefs for pin indexes and devicetree flags so these can
be safely recorded from devicetree property values without risking
loss of information if more flags are added in the future.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commits adds GPIO driver for LiteX SoC builder.
Due to the fact that GPIO in LiteX is unidirectional and can be
configured with different pins amount per port, additional entries
were added to the dts file.
Signed-off-by: Robert Winkler <rwinkler@internships.antmicro.com>
Signed-off-by: Mateusz Holenko <mholenko@antmicro.com>
Signed-off-by: Piotr Zierhoffer <pzierhoffer@antmicro.com>
Update sample application to use new GPIO API:
- GPIO flags defined by the devicetree
- replace gpio_pin_write with gpio_pin_set function
Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
For this board all 16 pins on the SX1509B should be configured as
outputs. Six of them are active-low LEDs. Provide configuration so
those six are initialized to output high, and the remainder to output
low.
Two of the pins control the behavior of the CCS811 gas sensor. By
driving them low on boot the baseline current draw of the board is
reduced by 100 uA.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
IO extenders may provide input signals to LEDs or sensors where
leaving the signal undriven may result in increased power consumption
or misbehavior. The SX1509B powers up with all signals configured as
inputs. Provide a way to indicate which pins should be set as output,
and their initial signal level, when the device is configured.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Update ALERT active level in all devicetree files. Capture GPIO flags
in static configuration. Add internal API to enable and disable
interrupt, to release the handlers when an alert occurs, and to
re-enable the signal when the handler completes. Check for alerts
received during periods when the interrupt was disabled.
Extend the example to handle both above and below range triggers and
alerts that are present on startup.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
In initialization code, pairs of gpio_pin_configure/gpio_pin_write are
replaced with calls to gpio_pin_configure that configure a given pin as
output with the proper initial state.
dts file for the board is also updated with the new GPIO flags.
Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
In initialization code, pairs of gpio_pin_configure/gpio_pin_write are
replaced with calls to gpio_pin_configure that configure a given pin as
output with the proper initial state.
dts file for the board is also updated with the new GPIO flags.
Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
The cached state of the output must be managed under mutex, but the
original toggle implementation read the current state outside the
mutex and used it to update the state. Rework the internal API so
that toggle is done within the mutex, distinct from masked set.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Provide correct active level and pull on all signals. Use
init-to-active when configuring antenna switch.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Convert the GPIO based driver to the new GPIO API. (Only the
gpio_configure() call is affected).
Move configuration to DT where appropriate for both SPI and GPIO
drivers, only leaving the SPI vs. GPIO decision in Kconfig (in
addition to the basic enable for the driver.) Move some files around
to clean up as a result of this change.
led_ws2812 sample changes:
- make the pattern easier to look at by emitting less light
- use led_strip alias from DT to get strip device, allocate
appropriate struct led_rgb buffer, etc.
- move the pins around and remove 96b_carbon support (I have no board
to test with)
GPIO driver specific changes:
- str is required to write OUTSET/OUTCLR, not strb. The registers
are word-sized.
- the str[b] registers must all be in r0-r7, so "l" is the correct GCC
inline assembly constraint for both "base" and "pin"
SPI driver specific changes:
- match the GPIO driver in not supporting the update_channels API
method, which never made sense for this type of strip
- return -ENOMEM when the user tries to send more pixel data
than we have buffer space for instead of -EINVAL
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Extend the physical level GPIO_OUTPUT_{HIGH,LOW} configuration with
GPIO_OUTPUT_{ACTIVE,INACTIVE} for logic level initialization.
This enables use of device-tree configuration flags in calls to
gpio_pin_configure() to set the logic level without having to
determine the corresponding physical level.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Switched from deprecated gpio_pin_write to gpio_pin_set and also add the
LED GPIO flags to the gpio configuration.
Signed-off-by: Karsten Koenig <karsten.koenig.030@gmail.com>
Mark the INT signal to be active low and use the new functions to get
gpio state and configure the gpio interrupt flanks.
Signed-off-by: Karsten Koenig <karsten.koenig.030@gmail.com>
This factors the common bits of device declaration into macros
so it would be easier to add new instances.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
Remove support for GPIO_ACCESS_BY_PORT in the config function
as configuration by port is going away.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
Since the GPIO expander is a I2C device, any read/write to
the registers has high latency. Therefore, semaphore is
introduced to prevent multiple threads to manipulate
the GPIOs at the same time.
Also make sure that we are not doing I2C transactions
within ISRs.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
Only update the internal register cache after successful write,
or else it would get out of sync with hardware.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
The register pair for each port in the GPIO expander are
port 0 first then port 1. This would not work for big
endian systems with the u16_t port value. So need to
swap the byte ordering on such system.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
The structures defined in the header file are only used by
the driver source file, and should not be used by others.
So roll the header file into the source file so it won't
get #include.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
Use I2C burst write to write 2 bytes to each pair of registers
instead of 2 separate transactions of writing 1 byte.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
PCA95XX is a series of compatible I2C-based GPIO expanders,
with common registers on input/output, polarity and configuration.
This renames the original PCAL9535A driver to PCA95XX to indicate
that it can support this series. Additional features on variants
are guarded by kconfigs.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
Update driver code and board files to use new GPIO configuration flags
such as GPIO_ACTIVE_LOW. Also add implementation of new port_* driver
API as well as gpio_pin_interrupt_configure function.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
The interrupt functionality of this driver is incomplete,
but for the sake of not slowing down the GPIO API refactor,
I'm just returning -ENOTSUP until we can track down the issue.
Signed-off-by: Nathaniel Graff <nathaniel.graff@sifive.com>
The 1pin test fails to pass because it expects to be able to
manipulate more than 16 pins. Since the intent is to filter invalid
pins at the wrapper level remove the validation performed within the
driver.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Some drivers masked the set of signaled pins based on enabled
interrupts, some did not. For those that did not the 2-pin test could
fail. The documentation does not imply that pins unrelated to the
callback participate in the notification process, so do the filtering
in the generic callback loop.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Previously the check would fail if a higher pin was present in the
callback set. Callbacks should only be told about pins that are
relevant to the callback, so reject unless exactly the expected pin
was provided.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Update the code configuring pins that control the routing of certain
lines on the board, to take advantage of the introduced possibility
of configuring a pin as output with specified initial state.
Additionally, use `gpio_pin_get_raw` instead of `gpio_pin_get` for
checking the reset pin state, to save a few bytes in flash.
Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
Convert the sample to use the new GPIO API and additionally:
- add some error messages for unsuccessful GPIO API calls
- correct the index of `def_val` element used in the `right_button`
callback, to match the one used when the callback is installed
- use flags defined in devicetree for the pin that drives the LED
(for consistency, as this does not make much difference for a pin
that is only toggled)
Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
In order to reliably detect interrupts the interrupt must be
acknowledged before the callback is invoked.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
In the fine print of the manual it's stated that attempts to enable a
pull in one direction while the pull in the other direction is enabled
are ignored. This has been confirmed. Change logic to disable both
pulls, then enable the one that's configured, if any.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
In order to reliably detect interrupts the interrupt must be
acknowledged before the callback is invoked.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Correct DRDY active level to default active-high, switch to new
interrupt configuration.
Also fix a common bug where an already-active DRDY signal is not
properly handled.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Update driver code and board files to use new GPIO configuration flags
such as GPIO_ACTIVE_LOW. Also add implementation of new port_* driver
API as well as gpio_pin_interrupt_configure function.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>