Commit e3f8777e authored by Daniel Campora's avatar Daniel Campora
Browse files

cc3200: Implement new Pin API.

parent ec8589e4
......@@ -44,11 +44,12 @@
{ &pin_type }, \
.name = MP_QSTR_ ## p_pin_name, \
.port = PORT_A ## p_port, \
.type = PIN_TYPE_STD, \
.pull = PIN_TYPE_STD, \
.bit = (p_bit), \
.pin_num = (p_pin_num), \
.af = PIN_MODE_0, \
.strength = PIN_STRENGTH_4MA, \
.mode = GPIO_DIR_MODE_IN, \
.value = 0, \
.isused = false, \
}
......@@ -107,7 +107,7 @@ class Pins(object):
for pin in self.cpu_pins:
if pin.is_board_pin():
pin.print()
self.print_named('cpu', self.cpu_pins)
self.print_named('board', self.cpu_pins)
print('')
def print_header(self, hdr_filename):
......
......@@ -94,7 +94,7 @@ void mperror_init0 (void) {
MAP_GPIODirModeSet(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN, GPIO_DIR_MODE_OUT);
#else
// configure the system led
pin_config ((pin_obj_t *)&MICROPY_SYS_LED_GPIO, PIN_MODE_0, GPIO_DIR_MODE_OUT, PIN_TYPE_STD, PIN_STRENGTH_6MA);
pin_config ((pin_obj_t *)&MICROPY_SYS_LED_GPIO, PIN_MODE_0, GPIO_DIR_MODE_OUT, PIN_TYPE_STD, 0, PIN_STRENGTH_6MA);
#endif
mperror_heart_beat.enabled = true;
mperror_heartbeat_switch_off();
......
......@@ -43,11 +43,11 @@ STATIC void pin_named_pins_obj_print(const mp_print_t *print, mp_obj_t self_in,
mp_printf(print, "<Pin.%q>", self->name);
}
const mp_obj_type_t pin_cpu_pins_obj_type = {
const mp_obj_type_t pin_board_pins_obj_type = {
{ &mp_type_type },
.name = MP_QSTR_cpu,
.name = MP_QSTR_board,
.print = pin_named_pins_obj_print,
.locals_dict = (mp_obj_t)&pin_cpu_pins_locals_dict,
.locals_dict = (mp_obj_t)&pin_board_pins_locals_dict,
};
pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) {
......
......@@ -89,7 +89,7 @@ STATIC pyb_adc_obj_t pyb_adc_obj[PYB_ADC_NUM_CHANNELS] = { {.pin = &pin_GP2, .ch
******************************************************************************/
STATIC void pybadc_init (pyb_adc_obj_t *self) {
// configure the pin in analog mode
pin_config (self->pin, PIN_MODE_0, GPIO_DIR_MODE_IN, PYBPIN_ANALOG_TYPE, PIN_STRENGTH_2MA);
pin_config (self->pin, -1, PIN_TYPE_ANALOG, PIN_TYPE_STD, -1, PIN_STRENGTH_2MA);
// enable the ADC channel
MAP_ADCChannelEnable(ADC_BASE, self->channel);
// enable and configure the timer
......
This diff is collapsed.
......@@ -28,8 +28,6 @@
#ifndef PYBPIN_H_
#define PYBPIN_H_
#define PYBPIN_ANALOG_TYPE 0xFF
enum {
PORT_A0 = GPIOA0_BASE,
PORT_A1 = GPIOA1_BASE,
......@@ -41,12 +39,13 @@ typedef struct {
const mp_obj_base_t base;
const qstr name;
const uint32_t port;
uint16_t type;
uint16_t pull;
const uint8_t bit;
const uint8_t pin_num;
uint8_t af;
int8_t af;
uint8_t strength;
uint8_t mode;
uint8_t mode; // this is now a combination of type and mode
int8_t value; // -1 means no defined value
bool isused;
} pin_obj_t;
......@@ -63,11 +62,11 @@ typedef struct {
const pin_named_pin_t *named_pins;
} pin_named_pins_obj_t;
extern const mp_obj_type_t pin_cpu_pins_obj_type;
extern const mp_obj_dict_t pin_cpu_pins_locals_dict;
extern const mp_obj_type_t pin_board_pins_obj_type;
extern const mp_obj_dict_t pin_board_pins_locals_dict;
void pin_init0(void);
void pin_config(pin_obj_t *self, uint af, uint mode, uint type, uint strength);
void pin_config(pin_obj_t *self, int af, uint mode, uint type, int value, uint strength);
pin_obj_t *pin_find(mp_obj_t user_obj);
pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name);
pin_obj_t *pin_find_pin_by_port_bit (const mp_obj_dict_t *named_pins, uint port, uint bit);
......
......@@ -122,11 +122,11 @@ STATIC mp_obj_t pybsd_init_helper (pybsd_obj_t *self, uint n_args, const mp_obj_
self->pin_clk = (pin_obj_t *)pin_find(items[2]);
// configure the data pin with pull-up enabled
pin_config ((pin_obj_t *)pin_find(items[0]), mp_obj_get_int(items[1]), 0, PIN_TYPE_STD_PU, PIN_STRENGTH_4MA);
pin_config ((pin_obj_t *)pin_find(items[0]), mp_obj_get_int(items[1]), 0, PIN_TYPE_STD_PU, -1, PIN_STRENGTH_4MA);
// configure the clock pin
pin_config (self->pin_clk, mp_obj_get_int(items[3]), 0, PIN_TYPE_STD, PIN_STRENGTH_4MA);
pin_config (self->pin_clk, mp_obj_get_int(items[3]), 0, PIN_TYPE_STD, -1, PIN_STRENGTH_4MA);
// configure the command pin with pull-up enabled
pin_config ((pin_obj_t *)pin_find(items[4]), mp_obj_get_int(items[5]), 0, PIN_TYPE_STD_PU, PIN_STRENGTH_4MA);
pin_config ((pin_obj_t *)pin_find(items[4]), mp_obj_get_int(items[5]), 0, PIN_TYPE_STD_PU, -1, PIN_STRENGTH_4MA);
self->pinsset = true;
} else {
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, mpexception_num_type_invalid_arguments));
......
......@@ -460,7 +460,7 @@ STATIC void pybsleep_obj_wakeup (void) {
}
STATIC void pybsleep_iopark (bool hibernate) {
mp_map_t *named_map = mp_obj_dict_get_map((mp_obj_t)&pin_cpu_pins_locals_dict);
mp_map_t *named_map = mp_obj_dict_get_map((mp_obj_t)&pin_board_pins_locals_dict);
for (uint i = 0; i < named_map->used; i++) {
pin_obj_t * pin = (pin_obj_t *)named_map->table[i].value;
switch (pin->pin_num) {
......
......@@ -141,8 +141,8 @@ soft_reset:
#ifdef LAUNCHXL
// configure the stdio uart pins with the correct alternate functions
// param 3 ("mode") is DON'T CARE" for AFs others than GPIO
pin_config ((pin_obj_t *)&MICROPY_STDIO_UART_TX_PIN, MICROPY_STDIO_UART_TX_PIN_AF, 0, PIN_TYPE_STD_PU, PIN_STRENGTH_2MA);
pin_config ((pin_obj_t *)&MICROPY_STDIO_UART_RX_PIN, MICROPY_STDIO_UART_RX_PIN_AF, 0, PIN_TYPE_STD_PU, PIN_STRENGTH_2MA);
pin_config ((pin_obj_t *)&MICROPY_STDIO_UART_TX_PIN, MICROPY_STDIO_UART_TX_PIN_AF, 0, PIN_TYPE_STD_PU, -1, PIN_STRENGTH_2MA);
pin_config ((pin_obj_t *)&MICROPY_STDIO_UART_RX_PIN, MICROPY_STDIO_UART_RX_PIN_AF, 0, PIN_TYPE_STD_PU, -1, PIN_STRENGTH_2MA);
// instantiate the stdio uart
mp_obj_t args[2] = {
mp_obj_new_int(MICROPY_STDIO_UART),
......
......@@ -110,34 +110,32 @@ Q(tell)
// for Pin class
Q(Pin)
Q(cpu)
Q(board)
Q(init)
Q(value)
Q(low)
Q(high)
Q(toggle)
Q(info)
Q(name)
Q(af)
Q(id)
Q(mode)
Q(type)
Q(strength)
Q(pull)
Q(drive)
Q(IN)
Q(OUT)
Q(STD)
Q(STD_PU)
Q(STD_PD)
Q(OD)
Q(OD_PU)
Q(OD_PD)
Q(OPEN_DRAIN)
Q(ALT)
Q(ALT_OPEN_DRAIN)
Q(PULL_UP)
Q(PULL_DOWN)
Q(PULL_NONE)
Q(LOW_POWER)
Q(MED_POWER)
Q(HIGH_POWER)
Q(INT_RISING)
Q(INT_FALLING)
Q(INT_RISING_FALLING)
Q(INT_LOW_LEVEL)
Q(INT_HIGH_LEVEL)
Q(S2MA)
Q(S4MA)
Q(S6MA)
// for UART class
Q(UART)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment