Commit 53716fcc authored by danicampora's avatar danicampora
Browse files

cc3200: Rename GPIO module to Pin.

This change helps making the cc3200 port API a bit closer to stmhal.
The ramaining differences are due to the specific hardware details
of each chip. One feature that has been deliberately disabled is the
possibility to add custom names and custom pin mappings. Those
features are nice and convenient, but in this port, code size is a
major concern.
parent d0df10b2
......@@ -74,7 +74,7 @@ APP_HAL_SRC_C = $(addprefix hal/,\
APP_MISC_SRC_C = $(addprefix misc/,\
FreeRTOSHooks.c \
gpio_named_pins.c \
pin_named_pins.c \
help.c \
mperror.c \
mpexception.c \
......@@ -89,7 +89,7 @@ APP_MODS_SRC_C = $(addprefix mods/,\
modutime.c \
modwlan.c \
pybextint.c \
pybgpio.c \
pybpin.c \
pybrtc.c \
pybstdio.c \
pybsystick.c \
......
......@@ -36,13 +36,13 @@
#include "obj.h"
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "pybgpio.h"
#include "pybpin.h"
#define GPIO(p_gpio_name, p_port, p_bit, p_pin_num) \
#define PIN(p_pin_name, p_port, p_bit, p_pin_num) \
{ \
{ &gpio_type }, \
.name = MP_QSTR_ ## p_gpio_name, \
{ &pin_type }, \
.name = MP_QSTR_ ## p_pin_name, \
.port = PORT_A ## p_port, \
.bit = (p_bit), \
.pin_num = (p_pin_num) \
......
#!/usr/bin/env python
"""Creates the pin file for the CC3200."""
"""Generates the pins files for the CC3200."""
from __future__ import print_function
......@@ -40,11 +40,11 @@ class Pin(object):
self.board_pin = True
def print(self):
print('const gpio_obj_t pin_{:6s} = GPIO({:6s}, {:1d}, {:3d}, {:2d});'.format(
print('const pin_obj_t pin_{:6s} = PIN({:6s}, {:1d}, {:3d}, {:2d});'.format(
self.name, self.name, self.port, self.gpio_bit, self.pin_num))
def print_header(self, hdr_file):
hdr_file.write('extern const gpio_obj_t pin_{:s};\n'.
hdr_file.write('extern const pin_obj_t pin_{:s};\n'.
format(self.name))
......@@ -89,12 +89,12 @@ class Pins(object):
def print_named(self, label, pins):
print('')
print('STATIC const mp_map_elem_t gpio_{:s}_pins_locals_dict_table[] = {{'.format(label))
print('STATIC const mp_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{'.format(label))
for pin in pins:
if pin.is_board_pin():
print(' {{ MP_OBJ_NEW_QSTR(MP_QSTR_{:6s}), (mp_obj_t)&pin_{:6s} }},'.format(pin.cpu_pin_name(), pin.cpu_pin_name()))
print('};')
print('MP_DEFINE_CONST_DICT(gpio_{:s}_pins_locals_dict, gpio_{:s}_pins_locals_dict_table);'.format(label, label));
print('MP_DEFINE_CONST_DICT(pin_{:s}_pins_locals_dict, pin_{:s}_pins_locals_dict_table);'.format(label, label));
def print(self):
for pin in self.cpu_pins:
......
......@@ -3,7 +3,6 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2013, 2014 Damien P. George
* Copyright (c) 2015 Daniel Campora
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
......
......@@ -3,7 +3,6 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2013, 2014 Damien P. George
* Copyright (c) 2015 Daniel Campora
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
......
......@@ -37,18 +37,18 @@
#include "rom_map.h"
#include "gpio.h"
#include "pin.h"
#include "pybgpio.h"
#include "pybpin.h"
#include "runtime.h"
#include MICROPY_HAL_H
// Returns the pin mode. This value returned by this macro should be one of:
// GPIO_DIR_MODE_IN or GPIO_DIR_MODE_OUT
uint32_t gpio_get_mode(const gpio_obj_t *self) {
uint32_t pin_get_mode(const pin_obj_t *self) {
return MAP_GPIODirModeGet(self->port, self->bit);
}
uint32_t gpio_get_type(const gpio_obj_t *self) {
uint32_t pin_get_type(const pin_obj_t *self) {
uint32_t strenght;
uint32_t type;
......@@ -58,7 +58,7 @@ uint32_t gpio_get_type(const gpio_obj_t *self) {
return type;
}
uint32_t gpio_get_strenght (const gpio_obj_t *self) {
uint32_t pin_get_strenght (const pin_obj_t *self) {
uint32_t strenght;
uint32_t type;
......
......@@ -36,23 +36,23 @@
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "pybgpio.h"
#include "pybpin.h"
#include "runtime.h"
#include MICROPY_HAL_H
STATIC void gpio_named_pins_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
gpio_named_pins_obj_t *self = self_in;
STATIC void pin_named_pins_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
pin_named_pins_obj_t *self = self_in;
print(env, "<Pin.%s>", qstr_str(self->name));
}
const mp_obj_type_t gpio_cpu_pins_obj_type = {
const mp_obj_type_t pin_cpu_pins_obj_type = {
{ &mp_type_type },
.name = MP_QSTR_cpu,
.print = gpio_named_pins_obj_print,
.locals_dict = (mp_obj_t)&gpio_cpu_pins_locals_dict,
.print = pin_named_pins_obj_print,
.locals_dict = (mp_obj_t)&pin_cpu_pins_locals_dict,
};
const gpio_obj_t *gpio_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) {
const pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) {
mp_map_t *named_map = mp_obj_dict_get_map((mp_obj_t)named_pins);
mp_map_elem_t *named_elem = mp_map_lookup(named_map, name, MP_MAP_LOOKUP);
if (named_elem != NULL && named_elem->value != NULL) {
......
......@@ -47,7 +47,7 @@
#include "prcm.h"
#include "pyexec.h"
#include "pybuart.h"
#include "pybgpio.h"
#include "pybpin.h"
#include "pybstdio.h"
#include "pybrtc.h"
#include "pybsystick.h"
......@@ -303,7 +303,7 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_RTC), (mp_obj_t)&pyb_rtc_type },
#endif
{ MP_OBJ_NEW_QSTR(MP_QSTR_GPIO), (mp_obj_t)&gpio_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_Pin), (mp_obj_t)&pin_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_ExtInt), (mp_obj_t)&extint_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_UART), (mp_obj_t)&pyb_uart_type },
......
......@@ -45,7 +45,7 @@
#include "rom_map.h"
#include "pin.h"
#include "gpio.h"
#include "pybgpio.h"
#include "pybpin.h"
#include "pybextint.h"
#include "mpexception.h"
#include "interrupt.h"
......@@ -55,7 +55,7 @@
/// \moduleref pyb
/// \class ExtInt - configure I/O pins to interrupt on external events
///
/// There are a maximum of 25 GPIO interrupt lines.
/// There are a maximum of 25 gpio interrupt lines.
///
/// Example callback:
///
......@@ -72,10 +72,10 @@
/// See: http://www.eng.utah.edu/~cs5780/debouncing.pdf for a detailed
/// explanation, along with various techniques for debouncing.
///
/// All gpio objects go through the gpio mapper to come up with one of the
/// All pin objects go through the pin mapper to come up with one of the
/// gpio pins.
///
/// extint = pyb.ExtInt(gpio, mode, pull, callback)
/// extint = pyb.ExtInt(pin, mode, pull, callback)
///
/// There is also a C API, so that drivers which require EXTI interrupt lines
/// can also use this code. See pybextint.h for the available functions.
......@@ -149,7 +149,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_swint_obj, extint_obj_swint);
/// \classmethod \constructor(pin, mode, pull, callback)
/// Create an ExtInt object:
///
/// - `gpio` is the gpio on which to enable the interrupt (can be a gpio object or any valid gpio name).
/// - `pin` is the pin on which to enable the interrupt (can be a pin object or any valid pin name).
/// - `mode` can be one of:
/// - `ExtInt.IRQ_RISING` - trigger on a rising edge;
/// - `ExtInt.IRQ_FALLING` - trigger on a falling edge;
......@@ -162,7 +162,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_swint_obj, extint_obj_swint);
/// callback function must accept exactly 1 argument, which is the line that
/// triggered the interrupt.
STATIC const mp_arg_t pyb_extint_make_new_args[] = {
{ MP_QSTR_gpio, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_pull, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_callback, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
......@@ -271,12 +271,12 @@ void extint_init0(void) {
}
extint_obj_t* extint_register(mp_obj_t pin_obj, uint32_t intmode, uint32_t pull, mp_obj_t callback) {
const gpio_obj_t *gpio = NULL;
const pin_obj_t *pin = NULL;
extint_obj_t* self;
void *handler;
uint32_t intnum;
gpio = gpio_find(pin_obj);
pin = pin_find(pin_obj);
if (intmode != GPIO_FALLING_EDGE &&
intmode != GPIO_RISING_EDGE &&
......@@ -294,8 +294,8 @@ extint_obj_t* extint_register(mp_obj_t pin_obj, uint32_t intmode, uint32_t pull,
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_value_invalid_arguments));
}
if (NULL == (self = extint_find(gpio->port, gpio->bit))) {
self = extint_add(gpio->pin_num, gpio->port, gpio->bit);
if (NULL == (self = extint_find(pin->port, pin->bit))) {
self = extint_add(pin->pin_num, pin->port, pin->bit);
}
else {
// we need to update the callback atomically, so we disable the line
......@@ -307,10 +307,10 @@ extint_obj_t* extint_register(mp_obj_t pin_obj, uint32_t intmode, uint32_t pull,
self->callback = NULL;
// before enabling the interrupt, configure the gpio pin
gpio_config(gpio, PIN_MODE_0, GPIO_DIR_MODE_IN, pull, PIN_STRENGTH_4MA);
pin_config(pin, PIN_MODE_0, GPIO_DIR_MODE_IN, pull, PIN_STRENGTH_4MA);
MAP_GPIOIntTypeSet(gpio->port, gpio->bit, intmode);
switch (gpio->port) {
MAP_GPIOIntTypeSet(pin->port, pin->bit, intmode);
switch (pin->port) {
case GPIOA0_BASE:
handler = GPIOA0IntHandler;
intnum = INT_GPIOA0;
......@@ -330,7 +330,7 @@ extint_obj_t* extint_register(mp_obj_t pin_obj, uint32_t intmode, uint32_t pull,
break;
}
MAP_GPIOIntRegister(gpio->port, handler);
MAP_GPIOIntRegister(pin->port, handler);
// set the interrupt to the lowest priority, to make sure that no ther
// isr will be preemted by this one
MAP_IntPrioritySet(intnum, INT_PRIORITY_LVL_7);
......
......@@ -45,12 +45,12 @@
#include "pin.h"
#include "prcm.h"
#include "gpio.h"
#include "pybgpio.h"
#include "pybpin.h"
#include "mpexception.h"
/// \moduleref pyb
/// \class GPIO - control I/O pins
/// \class Pin - control I/O pins
///
/// A pin is the basic object to control I/O pins. It has methods to set
/// the mode of the pin (input or output) and methods to get and set the
......@@ -58,95 +58,49 @@
///
/// Usage Model:
///
/// All CPU Pins are predefined as pyb.GPIO.cpu.Name
/// All CPU Pins are predefined as pyb.Pin.cpu.Name
///
/// GPIO9_pin = pyb.GPIO.cpu.GPIO9
/// GPIO9_pin = pyb.Pin.cpu.GPIO9
///
/// g = pyb.GPIO(pyb.GPIO.cpu.GPIO9, 0, pyb.GPIO.IN)
/// g = pyb.Pin(pyb.Pin.cpu.GPIO9, 0, pyb.Pin.IN)
///
/// CPU pins which correspond to the board pins are available
/// as `pyb.cpu.Name`.
///
/// You can also use strings:
///
/// g = pyb.GPIO('GPIO9', 0)
///
/// Users can add their own names:
///
/// MyMapperDict = { 'LeftMotorDir' : pyb.GPIO.cpu.GPIO11 }
/// pyb.GPIO.dict(MyMapperDict)
/// g = pyb.GPIO("LeftMotorDir", 0)
///
/// and can query mappings
///
/// g = pyb.GPIO("LeftMotorDir")
///
/// Users can also add their own mapping function:
///
/// def MyMapper(gpio_name):
/// if gpio_name == "LeftMotorDir":
/// return pyb.GPIO.cpu.GPIO11
///
/// pyb.GPIO.mapper(MyMapper)
///
/// So, if you were to call: `pyb.GPIO("LeftMotorDir", pyb.GPIO.OUT)`
/// then `"LeftMotorDir"` is passed directly to the mapper function.
/// g = pyb.Pin('GPIO9', 0)
///
/// To summarise, the following order determines how things get mapped into
/// an ordinal pin number:
///
/// 1. Directly specify a GPIO object
/// 2. User supplied mapping function
/// 3. User supplied mapping (object must be usable as a dictionary key)
/// 4. Supply a string which matches a CPU port/pin
void gpio_init0(void) {
MP_STATE_PORT(gpio_class_mapper) = mp_const_none;
MP_STATE_PORT(gpio_class_map_dict) = mp_const_none;
/// 1. Directly specify a Pin object
/// 2. Supply a string which matches a CPU port/pin
void pin_init0(void) {
}
// C API used to convert a user-supplied pin name into an ordinal pin number.
const gpio_obj_t *gpio_find(mp_obj_t user_obj) {
const gpio_obj_t *gpio_obj;
const pin_obj_t *pin_find(mp_obj_t user_obj) {
const pin_obj_t *pin_obj;
// If a pin was provided, then use it
if (MP_OBJ_IS_TYPE(user_obj, &gpio_type)) {
gpio_obj = user_obj;
return gpio_obj;
}
if (MP_STATE_PORT(gpio_class_mapper) != mp_const_none) {
gpio_obj = mp_call_function_1(MP_STATE_PORT(gpio_class_mapper), user_obj);
if (gpio_obj != mp_const_none) {
if (!MP_OBJ_IS_TYPE(gpio_obj, &gpio_type)) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable));
}
return gpio_obj;
}
// The pin mapping function returned mp_const_none, fall through to
// other lookup methods.
}
if (MP_STATE_PORT(gpio_class_map_dict) != mp_const_none) {
mp_map_t *gpio_map_map = mp_obj_dict_get_map(MP_STATE_PORT(gpio_class_map_dict));
mp_map_elem_t *elem = mp_map_lookup(gpio_map_map, user_obj, MP_MAP_LOOKUP);
if (elem != NULL && elem->value != NULL) {
gpio_obj = elem->value;
return gpio_obj;
}
if (MP_OBJ_IS_TYPE(user_obj, &pin_type)) {
pin_obj = user_obj;
return pin_obj;
}
// See if the pin name matches a cpu pin
gpio_obj = gpio_find_named_pin(&gpio_cpu_pins_locals_dict, user_obj);
if (gpio_obj) {
return gpio_obj;
pin_obj = pin_find_named_pin(&pin_cpu_pins_locals_dict, user_obj);
if (pin_obj) {
return pin_obj;
}
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
}
void gpio_config(const gpio_obj_t *self, uint af, uint mode, uint type, uint strength) {
// PIN_MODE_0 means it stays as a GPIO, else, another peripheral will take control of it
void pin_config(const pin_obj_t *self, uint af, uint mode, uint type, uint strength) {
// PIN_MODE_0 means it stays as a Pin, else, another peripheral will take control of it
if (af == PIN_MODE_0) {
// enable the peripheral clock for the GPIO port of this pin
switch (self->port) {
......@@ -176,25 +130,25 @@ void gpio_config(const gpio_obj_t *self, uint af, uint mode, uint type, uint str
/// \method print()
/// Return a string describing the pin object.
STATIC void gpio_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
gpio_obj_t *self = self_in;
STATIC void pin_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
pin_obj_t *self = self_in;
uint32_t af = MAP_PinModeGet(self->pin_num);
uint32_t type = gpio_get_type(self);
uint32_t strength = gpio_get_strenght(self);
uint32_t type = pin_get_type(self);
uint32_t strength = pin_get_strenght(self);
// pin name
print(env, "GPIO(GPIO.cpu.%s, af=%u", qstr_str(self->name), af);
print(env, "Pin(Pin.cpu.%s, af=%u", qstr_str(self->name), af);
if (af == PIN_MODE_0) {
// IO mode
qstr mode_qst;
uint32_t mode = gpio_get_mode(self);
uint32_t mode = pin_get_mode(self);
if (mode == GPIO_DIR_MODE_IN) {
mode_qst = MP_QSTR_IN;
} else {
mode_qst = MP_QSTR_OUT;
}
print(env, ", mode=GPIO.%s", qstr_str(mode_qst)); // safe because mode_qst has no formatting chars
print(env, ", mode=Pin.%s", qstr_str(mode_qst)); // safe because mode_qst has no formatting chars
}
// pin type
......@@ -212,7 +166,7 @@ STATIC void gpio_print(void (*print)(void *env, const char *fmt, ...), void *env
} else {
type_qst = MP_QSTR_OD_PD;
}
print(env, ", pull=GPIO.%s", qstr_str(type_qst));
print(env, ", pull=Pin.%s", qstr_str(type_qst));
// Strength
qstr str_qst;
......@@ -223,54 +177,30 @@ STATIC void gpio_print(void (*print)(void *env, const char *fmt, ...), void *env
} else {
str_qst = MP_QSTR_S6MA;
}
print(env, ", strength=GPIO.%s)", qstr_str(str_qst));
print(env, ", strength=Pin.%s)", qstr_str(str_qst));
}
STATIC mp_obj_t gpio_obj_init_helper(const gpio_obj_t *pin, mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args);
STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *pin, mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args);
/// \classmethod \constructor(id, ...)
/// Create a new GPIO object associated with the id. If additional arguments are given,
/// Create a new Pin object associated with the id. If additional arguments are given,
/// they are used to initialise the pin. See `init`.
STATIC mp_obj_t gpio_make_new(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
STATIC mp_obj_t pin_make_new(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
// Run an argument through the mapper and return the result.
const gpio_obj_t *pin = gpio_find(args[0]);
const pin_obj_t *pin = pin_find(args[0]);
if (n_args > 1) {
// pin af given, so configure it
mp_map_t kw_args;
mp_map_init_fixed_table(&kw_args, n_kw, args + n_args);
gpio_obj_init_helper(pin, n_args - 1, args + 1, &kw_args);
pin_obj_init_helper(pin, n_args - 1, args + 1, &kw_args);
}
return (mp_obj_t)pin;
}
/// \classmethod mapper([fun])
/// Get or set the pin mapper function.
STATIC mp_obj_t gpio_mapper(mp_uint_t n_args, const mp_obj_t *args) {
if (n_args > 1) {
MP_STATE_PORT(gpio_class_mapper) = args[1];
return mp_const_none;
}
return MP_STATE_PORT(gpio_class_mapper);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(gpio_mapper_fun_obj, 1, 2, gpio_mapper);
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(gpio_mapper_obj, (mp_obj_t)&gpio_mapper_fun_obj);
/// \classmethod dict([dict])
/// Get or set the pin mapper dictionary.
STATIC mp_obj_t gpio_map_dict(mp_uint_t n_args, const mp_obj_t *args) {
if (n_args > 1) {
MP_STATE_PORT(gpio_class_map_dict) = args[1];
return mp_const_none;
}
return MP_STATE_PORT(gpio_class_map_dict);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(gpio_map_dict_fun_obj, 1, 2, gpio_map_dict);
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(gpio_map_dict_obj, (mp_obj_t)&gpio_map_dict_fun_obj);
/// \method init(mode, pull=Pin.PULL_NONE, af=-1)
/// Initialise the pin:
///
......@@ -293,18 +223,18 @@ STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(gpio_map_dict_obj, (mp_obj_t)&gpio_map_di
/// - `Pin.6MA` - 6ma drive strength;
///
/// Returns: `None`.
STATIC const mp_arg_t gpio_init_args[] = {
STATIC const mp_arg_t pin_init_args[] = {
{ MP_QSTR_af, MP_ARG_REQUIRED | MP_ARG_INT },
{ MP_QSTR_mode, MP_ARG_INT, {.u_int = GPIO_DIR_MODE_OUT} },
{ MP_QSTR_type, MP_ARG_INT, {.u_int = PIN_TYPE_STD} },
{ MP_QSTR_str, MP_ARG_INT, {.u_int = PIN_STRENGTH_4MA} },
};
#define gpio_INIT_NUM_ARGS MP_ARRAY_SIZE(gpio_init_args)
#define pin_INIT_NUM_ARGS MP_ARRAY_SIZE(pin_init_args)
STATIC mp_obj_t gpio_obj_init_helper(const gpio_obj_t *self, mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *self, mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
// parse args
mp_arg_val_t vals[gpio_INIT_NUM_ARGS];
mp_arg_parse_all(n_args, args, kw_args, gpio_INIT_NUM_ARGS, gpio_init_args, vals);
mp_arg_val_t vals[pin_INIT_NUM_ARGS];
mp_arg_parse_all(n_args, args, kw_args, pin_INIT_NUM_ARGS, pin_init_args, vals);
// get the af
uint af = vals[0].u_int;
......@@ -329,15 +259,15 @@ STATIC mp_obj_t gpio_obj_init_helper(const gpio_obj_t *self, mp_uint_t n_args, c
}
// configure the pin as requested
gpio_config (self, af, mode, type, strength);
pin_config (self, af, mode, type, strength);
return mp_const_none;
}
STATIC mp_obj_t gpio_obj_init(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return gpio_obj_init_helper(args[0], n_args - 1, args + 1, kw_args);
STATIC mp_obj_t pin_obj_init(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return pin_obj_init_helper(args[0], n_args - 1, args + 1, kw_args);
}
MP_DEFINE_CONST_FUN_OBJ_KW(gpio_init_obj, 1, gpio_obj_init);
MP_DEFINE_CONST_FUN_OBJ_KW(pin_init_obj, 1, pin_obj_init);
/// \method value([value])
/// Get or set the digital logic level of the pin:
......@@ -346,8 +276,8 @@ MP_DEFINE_CONST_FUN_OBJ_KW(gpio_init_obj, 1, gpio_obj_init);
/// - With `value` given, set the logic level of the pin. `value` can be
/// anything that converts to a boolean. If it converts to `True`, the pin
/// is set high, otherwise it is set low.
STATIC mp_obj_t gpio_value(mp_uint_t n_args, const mp_obj_t *args) {
gpio_obj_t *self = args[0];
STATIC mp_obj_t pin_value(mp_uint_t n_args, const mp_obj_t *args) {
pin_obj_t *self = args[0];
if (n_args == 1) {
// get the pin value
return MP_OBJ_NEW_SMALL_INT(MAP_GPIOPinRead(self->port, self->bit) ? 1 : 0);
......@@ -361,136 +291,112 @@ STATIC mp_obj_t gpio_value(mp_uint_t n_args, const mp_obj_t *args) {
return mp_const_none;
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(gpio_value_obj, 1, 2, gpio_value);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value);
/// \method low()
/// Set the pin to a low logic level.
STATIC mp_obj_t gpio_low(mp_obj_t self_in) {
gpio_obj_t *self = self_in;
STATIC mp_obj_t pin_low(mp_obj_t self_in) {
pin_obj_t *self = self_in;
MAP_GPIOPinWrite(self->port, self->bit, 0);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(gpio_low_obj, gpio_low);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_low_obj, pin_low);
/// \method high()
/// Set the pin to a high logic level.
STATIC mp_obj_t gpio_high(mp_obj_t self_in) {
gpio_obj_t *self = self_in;
STATIC mp_obj_t pin_high(mp_obj_t self_in) {
pin_obj_t *self = self_in;
MAP_GPIOPinWrite(self->port, self->bit, self->bit);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(gpio_high_obj, gpio_high);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_high_obj, pin_high);
/// \method toggle()
/// Toggles the value of the pin
STATIC mp_obj_t gpio_toggle(mp_obj_t self_in) {
gpio_obj_t *self = self_in;
STATIC mp_obj_t pin_toggle(mp_obj_t self_in) {
pin_obj_t *self = self_in;
MAP_GPIOPinWrite(self->port, self->bit, ~MAP_GPIOPinRead(self->port, self->bit));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(gpio_toggle_obj, gpio_toggle);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_toggle_obj, pin_toggle);
/// \method name()
/// Get the pin name.
STATIC mp_obj_t gpio_name(mp_obj_t self_in) {
gpio_obj_t *self = self_in;
STATIC mp_obj_t pin_name(mp_obj_t self_in) {
pin_obj_t *self = self_in;
return MP_OBJ_NEW_QSTR(self->name);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(gpio_name_obj, gpio_name);
/// \method name()
/// Returns the cpu name for this pin.
STATIC mp_obj_t gpio_cpu_name(mp_obj_t self_in) {
gpio_obj_t *self = self_in;
mp_obj_t result = mp_obj_new_list(0, NULL);
mp_obj_list_append(result, MP_OBJ_NEW_QSTR(self->name));
mp_map_t *map = mp_obj_dict_get_map((mp_obj_t)&gpio_cpu_pins_locals_dict);
mp_map_elem_t *elem = map->table;