mimxrt: Extend the Pin module for SoftI2C, SoftSPI support.
This change consists mostly of changing and extending the required definitions in mphalport.h.
This commit is contained in:
parent
5f68f0d08a
commit
c732b80f05
@ -68,6 +68,20 @@ const mp_obj_type_t machine_pin_board_pins_obj_type = {
|
||||
.locals_dict = (mp_obj_t)&machine_pin_board_pins_locals_dict,
|
||||
};
|
||||
|
||||
// Simplified mode setting used by the extmod modules
|
||||
void machine_pin_set_mode(const machine_pin_obj_t *self, uint8_t mode) {
|
||||
gpio_pin_config_t pin_config = {kGPIO_DigitalInput, 1, kGPIO_NoIntmode};
|
||||
|
||||
pin_config.direction = (mode == PIN_MODE_IN ? kGPIO_DigitalInput : kGPIO_DigitalOutput);
|
||||
GPIO_PinInit(self->gpio, self->pin, &pin_config);
|
||||
if (mode == PIN_MODE_OPEN_DRAIN) {
|
||||
uint32_t pad_config = *(uint32_t *)self->configRegister;
|
||||
pad_config |= IOMUXC_SW_PAD_CTL_PAD_ODE(0b1) | IOMUXC_SW_PAD_CTL_PAD_DSE(0b110);
|
||||
IOMUXC_SetPinMux(self->muxRegister, PIN_AF_MODE_ALT5, 0, 0, self->configRegister, 1U); // Software Input On Field: Input Path is determined by functionality
|
||||
IOMUXC_SetPinConfig(self->muxRegister, PIN_AF_MODE_ALT5, 0, 0, self->configRegister, pad_config);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t machine_pin_obj_call(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, 0, 1, false);
|
||||
machine_pin_obj_t *self = self_in;
|
||||
|
@ -31,12 +31,22 @@
|
||||
#include "ticks.h"
|
||||
#include "pin.h"
|
||||
|
||||
#define MP_HAL_PIN_FMT "%q"
|
||||
|
||||
#define mp_hal_pin_obj_t const machine_pin_obj_t *
|
||||
#define mp_hal_get_pin_obj(o) pin_find(o)
|
||||
#define mp_hal_pin_name(p) ((p)->name)
|
||||
#define mp_hal_pin_input(p) machine_pin_set_mode(p, PIN_MODE_IN);
|
||||
#define mp_hal_pin_output(p) machine_pin_set_mode(p, PIN_MODE_OUT);
|
||||
#define mp_hal_pin_open_drain(p) machine_pin_set_mode(p, PIN_MODE_OPEN_DRAIN);
|
||||
#define mp_hal_pin_high(p) (GPIO_PinWrite(p->gpio, p->pin, 1U))
|
||||
#define mp_hal_pin_low(p) (GPIO_PinWrite(p->gpio, p->pin, 0U))
|
||||
#define mp_hal_pin_write(p, value) (GPIO_PinWrite(p->gpio, p->pin, value))
|
||||
#define mp_hal_pin_toggle(p) (GPIO_PortToggle(p->gpio, (1 << p->pin)))
|
||||
#define mp_hal_pin_read(p) (GPIO_PinRead(p->gpio, p->pin))
|
||||
#define mp_hal_pin_read(p) (GPIO_PinReadPadStatus(p->gpio, p->pin))
|
||||
|
||||
#define mp_hal_pin_od_low(p) mp_hal_pin_low(p)
|
||||
#define mp_hal_pin_od_high(p) mp_hal_pin_high(p)
|
||||
|
||||
void mp_hal_set_interrupt_char(int c);
|
||||
|
||||
@ -57,6 +67,8 @@ static inline void mp_hal_delay_us(mp_uint_t us) {
|
||||
ticks_delay_us64(us);
|
||||
}
|
||||
|
||||
#define mp_hal_delay_us_fast(us) mp_hal_delay_us(us)
|
||||
|
||||
static inline mp_uint_t mp_hal_ticks_cpu(void) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -140,5 +140,6 @@ const machine_pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_
|
||||
const machine_pin_af_obj_t *pin_find_af(const machine_pin_obj_t *pin, uint8_t fn);
|
||||
const machine_pin_af_obj_t *pin_find_af_by_index(const machine_pin_obj_t *pin, mp_uint_t af_idx);
|
||||
const machine_pin_af_obj_t *pin_find_af_by_name(const machine_pin_obj_t *pin, const char *name);
|
||||
void machine_pin_set_mode(const machine_pin_obj_t *pin, uint8_t mode);
|
||||
|
||||
#endif // MICROPY_INCLUDED_MIMXRT_PIN_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user