circuitpython/zephyr/modmachine.h
Daniel Thompson 67b6d9d499 zephyr: Initial implementation of machine.Pin.
The integration with Zephyr is fairly clean but as MicroPython Hardware API
requires pin ID to be a single value, but Zephyr operates GPIO in terms of
ports and pins, not just pins, a "hierarchical" ID is required, using tuple
of (port, pin). Port is a string, effectively a device name of a GPIO port,
per Zephyr conventions these are "GPIO_0", "GPIO_1", etc.; pin is integer
number of pin with the port (supposed to be in range 0-31).

Example of pin initialization:

pin = Pin(("GPIO_1", 21), Pin.OUT)

(an LED on FRDM-K64F's Port B, Pin 21).

There is support for in/out pins and pull up/pull down but currently
there is no interrupt support.

Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
Signed-off-by: Vincenzo Frascino <vincenzo.frascino@linaro.org>
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2016-10-27 00:47:26 +03:00

17 lines
389 B
C

#ifndef __MICROPY_INCLUDED_ZEPHYR_MODMACHINE_H__
#define __MICROPY_INCLUDED_ZEPHYR_MODMACHINE_H__
#include "py/obj.h"
extern const mp_obj_type_t machine_pin_type;
MP_DECLARE_CONST_FUN_OBJ_0(machine_info_obj);
typedef struct _machine_pin_obj_t {
mp_obj_base_t base;
struct device *port;
uint32_t pin;
} machine_pin_obj_t;
#endif // __MICROPY_INCLUDED_ZEPHYR_MODMACHINE_H__