3.17. pin — Digital pins

3.17.1. Debug file system commands

Three debug file system commands are available, all located in the directory drivers/pin/. These commands directly access the pin device registers, without using the pin driver object.

Command Description
set_mode <pin> <mode> Set the mode of the pin <pin> to <mode>, where
<mode> is one of output and input.
read <pin> Read current input or output value of the pin <pin>.
high or low is printed.
write <pin> <value> Write the value <value> to pin <pin>, where
<value> is one of high and low.

Example output from the shell:

$ drivers/pin/set_mode d2 output
$ drivers/pin/read d2
low
$ drivers/pin/write d2 high
$ drivers/pin/read d2
high
$ drivers/pin/set_mode d3 input
$ drivers/pin/read d3
low

Source code: src/drivers/pin.h, src/drivers/pin.c

Test code: tst/drivers/pin/main.c


Defines

PIN_OUTPUT 0
PIN_INPUT 1

Configure the pin as an input pin.

Functions

int pin_module_init(void)

Initialize the pin module. This function must be called before calling any other function in this module.

The module will only be initialized once even if this function is called multiple times.

Return
zero(0) or negative error code.

int pin_init(struct pin_driver_t *self_p, struct pin_device_t *dev_p, int mode)

Initialize given driver object with given device and mode.

Return
zero(0) or negative error code.
Parameters
  • self_p: Driver object to be initialized.
  • dev_p: Device to use.
  • mode: Pin mode. One of PIN_INPUT or PIN_OUTPUT.

int pin_write(struct pin_driver_t *self_p, int value)

Write given value to given pin.

Return
zero(0) or negative error code.
Parameters
  • self_p: Driver object.
  • value: 1 for high and 0 for low output.

int pin_read(struct pin_driver_t *self_p)

Read the current value of given pin.

Return
1 for high and 0 for low input, otherwise negative error code.
Parameters
  • self_p: Driver object.

int pin_toggle(struct pin_driver_t *self_p)

Toggle the pin output value (high/low).

Return
zero(0) or negative error code.
Parameters
  • self_p: Driver object.

int pin_set_mode(struct pin_driver_t *self_p, int mode)

Set the pin mode of given pin.

Return
zero(0) or negative error code.
Parameters
  • self_p: Driver object.
  • mode: New pin mode.

static int pin_device_set_mode(const struct pin_device_t *dev_p, int mode)

Pin device mode to set. One of PIN_INPUT or PIN_OUTPUT.

Return
zero(0) or negative error code.
Parameters
  • self_p: Pin device.
  • mode: New pin mode.

static int pin_device_read(const struct pin_device_t *dev_p)

Read the value of given pin device.

Return
1 for high and 0 for low input, otherwise negative error code.
Parameters
  • self_p: Pin device.

static int pin_device_write_high(const struct pin_device_t *dev_p)

Write high to given pin device.

Return
zero(0) or negative error code.
Parameters
  • self_p: Pin device.

static int pin_device_write_low(const struct pin_device_t *dev_p)

Write low to given pin device.

Return
zero(0) or negative error code.
Parameters
  • self_p: Pin device.

int pin_is_valid_device(struct pin_device_t *dev_p)

Check if given pin device is valid.

Return
true(1) if the pin device is valid, otherwise false(0).
Parameters
  • dev_p: Pin device to validate.

Variables

struct pin_device_t pin_device[PIN_DEVICE_MAX]