2020-01-20 11:25:51 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2019 Damien P. George
|
|
|
|
* Copyright (c) 2020 Jim Mussared
|
|
|
|
*
|
|
|
|
* 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_MPHALPORT_H
|
|
|
|
#define MICROPY_INCLUDED_MIMXRT_MPHALPORT_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2021-05-16 04:27:54 +01:00
|
|
|
#include "ticks.h"
|
2021-07-03 17:39:17 +01:00
|
|
|
#include "py/ringbuf.h"
|
2020-08-21 15:03:21 +01:00
|
|
|
#include "pin.h"
|
2021-08-19 21:00:38 +01:00
|
|
|
#include "fsl_clock.h"
|
2020-01-20 11:25:51 +00:00
|
|
|
|
2021-09-19 21:08:51 +01:00
|
|
|
#define MICROPY_HAL_VERSION "2.8.0"
|
|
|
|
|
2021-05-25 13:49:21 +01:00
|
|
|
#define MP_HAL_PIN_FMT "%q"
|
2021-07-03 17:39:17 +01:00
|
|
|
extern ringbuf_t stdin_ringbuf;
|
2021-05-25 13:49:21 +01:00
|
|
|
|
2020-08-21 15:03:21 +01:00
|
|
|
#define mp_hal_pin_obj_t const machine_pin_obj_t *
|
2021-05-25 13:49:21 +01:00
|
|
|
#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);
|
2021-08-19 21:00:38 +01:00
|
|
|
#define mp_hal_pin_high(p) (p->gpio->DR_SET = 1 << p->pin)
|
|
|
|
#define mp_hal_pin_low(p) (p->gpio->DR_CLEAR = 1 << p->pin)
|
2020-08-21 15:03:21 +01:00
|
|
|
#define mp_hal_pin_write(p, value) (GPIO_PinWrite(p->gpio, p->pin, value))
|
2020-04-12 21:00:06 +01:00
|
|
|
#define mp_hal_pin_toggle(p) (GPIO_PortToggle(p->gpio, (1 << p->pin)))
|
2021-05-25 13:49:21 +01:00
|
|
|
#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)
|
2020-04-12 21:00:06 +01:00
|
|
|
|
2021-11-10 12:59:09 +00:00
|
|
|
#define mp_hal_quiet_timing_enter() raise_irq_pri(1)
|
|
|
|
#define mp_hal_quiet_timing_exit(irq_state) restore_irq_pri(irq_state)
|
2021-05-26 12:19:38 +01:00
|
|
|
|
2020-01-20 11:25:51 +00:00
|
|
|
void mp_hal_set_interrupt_char(int c);
|
|
|
|
|
|
|
|
static inline mp_uint_t mp_hal_ticks_ms(void) {
|
2021-05-16 04:27:54 +01:00
|
|
|
return ticks_ms32();
|
2020-01-20 11:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline mp_uint_t mp_hal_ticks_us(void) {
|
2021-05-16 04:27:54 +01:00
|
|
|
return ticks_us32();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mp_hal_delay_ms(mp_uint_t ms) {
|
|
|
|
uint64_t us = (uint64_t)ms * 1000;
|
|
|
|
ticks_delay_us64(us);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mp_hal_delay_us(mp_uint_t us) {
|
|
|
|
ticks_delay_us64(us);
|
2020-01-20 11:25:51 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 13:49:21 +01:00
|
|
|
#define mp_hal_delay_us_fast(us) mp_hal_delay_us(us)
|
|
|
|
|
2021-10-12 21:49:18 +01:00
|
|
|
static inline void mp_hal_ticks_cpu_enable(void) {
|
|
|
|
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
|
|
|
DWT->LAR = 0xc5acce55;
|
|
|
|
DWT->CYCCNT = 0;
|
2021-08-19 21:00:38 +01:00
|
|
|
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
|
|
|
|
}
|
|
|
|
|
2020-01-20 11:25:51 +00:00
|
|
|
static inline mp_uint_t mp_hal_ticks_cpu(void) {
|
2021-08-19 21:00:38 +01:00
|
|
|
return DWT->CYCCNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline mp_uint_t mp_hal_get_cpu_freq(void) {
|
|
|
|
return CLOCK_GetCpuClkFreq();
|
2020-01-20 11:25:51 +00:00
|
|
|
}
|
|
|
|
|
2021-07-03 17:39:17 +01:00
|
|
|
enum {
|
|
|
|
MP_HAL_MAC_WLAN0 = 0,
|
|
|
|
MP_HAL_MAC_WLAN1,
|
|
|
|
MP_HAL_MAC_BDADDR,
|
|
|
|
MP_HAL_MAC_ETH0,
|
2021-11-04 20:54:44 +00:00
|
|
|
MP_HAL_MAC_ETH1,
|
2021-07-03 17:39:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void mp_hal_generate_laa_mac(int idx, uint8_t buf[6]);
|
|
|
|
void mp_hal_get_mac(int idx, uint8_t buf[6]);
|
|
|
|
void mp_hal_get_mac_ascii(int idx, size_t chr_off, size_t chr_len, char *dest);
|
2021-11-30 19:23:03 +00:00
|
|
|
void mp_hal_get_unique_id(uint8_t id[]);
|
2021-05-07 14:21:09 +01:00
|
|
|
|
2020-01-20 11:25:51 +00:00
|
|
|
#endif // MICROPY_INCLUDED_MIMXRT_MPHALPORT_H
|