2020-04-12 21:00:06 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2020 Philipp Ebensberger
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MICROPY_INCLUDED_MIMXRT_PIN_H
|
|
|
|
#define MICROPY_INCLUDED_MIMXRT_PIN_H
|
|
|
|
|
2020-08-21 15:03:21 +01:00
|
|
|
#include <stdint.h>
|
2020-04-12 21:00:06 +01:00
|
|
|
#include "py/obj.h"
|
2021-07-09 05:19:15 +01:00
|
|
|
#include "shared/runtime/mpirq.h"
|
2020-08-21 15:03:21 +01:00
|
|
|
#include "fsl_gpio.h"
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------------------------ //
|
|
|
|
|
|
|
|
#define IS_GPIO_MODE(MODE) (((MODE) == PIN_MODE_IN) || \
|
|
|
|
((MODE) == PIN_MODE_OUT) || \
|
|
|
|
((MODE) == PIN_MODE_OPEN_DRAIN) || \
|
|
|
|
((MODE) == PIN_MODE_ALT))
|
|
|
|
|
2023-05-02 11:34:12 +01:00
|
|
|
#define IS_GPIO_IT_MODE(MODE) (((MODE) == PIN_MODE_IT_RISING) || \
|
|
|
|
((MODE) == PIN_MODE_IT_FALLING) || \
|
|
|
|
((MODE) == PIN_MODE_IT_BOTH))
|
|
|
|
|
2020-08-21 15:03:21 +01:00
|
|
|
#define IS_GPIO_DRIVE(DRIVE) (((DRIVE) == PIN_DRIVE_OFF) || \
|
2022-03-07 15:56:14 +00:00
|
|
|
((DRIVE) == PIN_DRIVE_0) || \
|
|
|
|
((DRIVE) == PIN_DRIVE_1) || \
|
|
|
|
((DRIVE) == PIN_DRIVE_2) || \
|
|
|
|
((DRIVE) == PIN_DRIVE_3) || \
|
|
|
|
((DRIVE) == PIN_DRIVE_4) || \
|
|
|
|
((DRIVE) == PIN_DRIVE_5) || \
|
|
|
|
((DRIVE) == PIN_DRIVE_6))
|
2020-08-21 15:03:21 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------------------------ //
|
2020-04-12 21:00:06 +01:00
|
|
|
|
|
|
|
enum {
|
|
|
|
PIN_MODE_IN = 0,
|
|
|
|
PIN_MODE_OUT,
|
2020-08-21 15:03:21 +01:00
|
|
|
PIN_MODE_OPEN_DRAIN,
|
2020-04-12 21:00:06 +01:00
|
|
|
PIN_MODE_ALT,
|
2022-01-02 12:21:06 +00:00
|
|
|
PIN_MODE_SKIP,
|
2023-05-02 11:34:12 +01:00
|
|
|
PIN_MODE_IT_RISING,
|
|
|
|
PIN_MODE_IT_FALLING,
|
|
|
|
PIN_MODE_IT_BOTH,
|
2020-04-12 21:00:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2021-08-01 10:20:39 +01:00
|
|
|
PIN_AF_MODE_ALT0 = 0,
|
|
|
|
PIN_AF_MODE_ALT1,
|
2020-04-12 21:00:06 +01:00
|
|
|
PIN_AF_MODE_ALT2,
|
|
|
|
PIN_AF_MODE_ALT3,
|
|
|
|
PIN_AF_MODE_ALT4,
|
|
|
|
PIN_AF_MODE_ALT5,
|
|
|
|
PIN_AF_MODE_ALT6,
|
|
|
|
PIN_AF_MODE_ALT7,
|
|
|
|
PIN_AF_MODE_ALT8,
|
2021-08-20 20:41:58 +01:00
|
|
|
PIN_AF_MODE_ALT9,
|
2021-10-20 20:24:20 +01:00
|
|
|
PIN_AF_MODE_ALT10,
|
2020-04-12 21:00:06 +01:00
|
|
|
};
|
|
|
|
|
2020-08-21 15:03:21 +01:00
|
|
|
enum {
|
|
|
|
PIN_PULL_DOWN_100K = 0,
|
|
|
|
PIN_PULL_UP_47K,
|
|
|
|
PIN_PULL_UP_100K,
|
|
|
|
PIN_PULL_UP_22K,
|
|
|
|
PIN_PULL_DISABLED,
|
|
|
|
PIN_PULL_HOLD,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PIN_DRIVE_OFF = 0b000,
|
2022-03-07 15:56:14 +00:00
|
|
|
PIN_DRIVE_0, // R0 (150 Ohm @3.3V / 260 Ohm @ 1.8V)
|
|
|
|
PIN_DRIVE_1, // R0/2
|
|
|
|
PIN_DRIVE_2, // R0/3
|
|
|
|
PIN_DRIVE_3, // R0/4
|
|
|
|
PIN_DRIVE_4, // R0/5
|
|
|
|
PIN_DRIVE_5, // R0/6
|
|
|
|
PIN_DRIVE_6, // R0/7
|
2020-08-21 15:03:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------------------------ //
|
|
|
|
|
2020-04-12 21:00:06 +01:00
|
|
|
typedef struct {
|
|
|
|
mp_obj_base_t base;
|
|
|
|
qstr name; // port name
|
2020-08-21 15:03:21 +01:00
|
|
|
uint8_t af_mode; // alternate function
|
2021-08-01 10:20:39 +01:00
|
|
|
uint8_t input_daisy;
|
2020-04-12 21:00:06 +01:00
|
|
|
void *instance; // pointer to peripheral instance for alternate function
|
2021-08-01 10:20:39 +01:00
|
|
|
uint32_t input_register;
|
2020-04-12 21:00:06 +01:00
|
|
|
uint32_t pad_config; // pad configuration for alternate function
|
2020-08-21 15:03:21 +01:00
|
|
|
} machine_pin_af_obj_t;
|
2020-04-12 21:00:06 +01:00
|
|
|
|
2021-04-24 20:34:07 +01:00
|
|
|
typedef struct {
|
|
|
|
ADC_Type *instance;
|
|
|
|
uint8_t channel;
|
|
|
|
} machine_pin_adc_obj_t;
|
|
|
|
|
2020-04-12 21:00:06 +01:00
|
|
|
typedef struct {
|
|
|
|
mp_obj_base_t base;
|
|
|
|
qstr name; // pad name
|
|
|
|
GPIO_Type *gpio; // gpio instance for pin
|
|
|
|
uint32_t pin; // pin number
|
|
|
|
uint32_t muxRegister;
|
|
|
|
uint32_t configRegister;
|
2021-04-24 20:34:07 +01:00
|
|
|
uint8_t af_list_len; // length of available alternate functions list
|
|
|
|
uint8_t adc_list_len; // length of available ADC options list
|
|
|
|
const machine_pin_af_obj_t *af_list; // pointer to list with alternate functions
|
|
|
|
const machine_pin_adc_obj_t *adc_list; // pointer to list with ADC options
|
2020-08-21 15:03:21 +01:00
|
|
|
} machine_pin_obj_t;
|
|
|
|
|
2021-06-05 13:06:04 +01:00
|
|
|
typedef struct _machine_pin_irq_obj_t {
|
|
|
|
mp_irq_obj_t base;
|
|
|
|
uint32_t flags;
|
|
|
|
uint32_t trigger;
|
|
|
|
} machine_pin_irq_obj_t;
|
|
|
|
|
2020-08-21 15:03:21 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------------------------ //
|
|
|
|
|
|
|
|
extern const mp_obj_type_t machine_pin_af_type;
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------------------------ //
|
2020-04-12 21:00:06 +01:00
|
|
|
|
|
|
|
// Include board specific pins
|
2020-08-21 15:03:21 +01:00
|
|
|
#include "genhdr/pins.h" // pins.h must included at this location
|
|
|
|
|
|
|
|
extern const mp_obj_type_t machine_pin_board_pins_obj_type;
|
|
|
|
extern const mp_obj_type_t machine_pin_cpu_pins_obj_type;
|
|
|
|
|
|
|
|
extern const mp_obj_dict_t machine_pin_cpu_pins_locals_dict;
|
|
|
|
extern const mp_obj_dict_t machine_pin_board_pins_locals_dict;
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------------------------ //
|
|
|
|
|
|
|
|
void pin_init(void);
|
|
|
|
uint32_t pin_get_mode(const machine_pin_obj_t *pin);
|
|
|
|
uint32_t pin_get_af(const machine_pin_obj_t *pin);
|
|
|
|
const machine_pin_obj_t *pin_find(mp_obj_t user_obj);
|
|
|
|
const machine_pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name);
|
|
|
|
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);
|
2021-05-25 13:49:21 +01:00
|
|
|
void machine_pin_set_mode(const machine_pin_obj_t *pin, uint8_t mode);
|
2023-05-02 11:34:12 +01:00
|
|
|
void machine_pin_config(const machine_pin_obj_t *self, uint8_t mode,
|
|
|
|
uint8_t pull, uint8_t drive, uint8_t speed, uint8_t alt);
|
2022-01-02 12:21:06 +00:00
|
|
|
uint32_t pin_generate_config(const uint32_t pull, const uint32_t mode, const uint32_t drive, uint32_t config_register);
|
2020-04-12 21:00:06 +01:00
|
|
|
|
|
|
|
#endif // MICROPY_INCLUDED_MIMXRT_PIN_H
|