forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mimxrt: Combined files and changes for using the esp_hosted driver.
At first with the board files for MIMXRT1020 only. MIMXRT1010 does not build due to RAM shortage. Signed-off-by: robert-hh <robert@hammelrath.com>
- Loading branch information
Showing
16 changed files
with
297 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule mynewt-nimble
updated
from 428495 to f1f6e5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
include("../manifest.py") | ||
|
||
require("bundle-networking") | ||
# Bluetooth | ||
require("aioble") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef MICROPY_INCLUDED_MBEDTLS_CONFIG_BOARD_H | ||
#define MICROPY_INCLUDED_MBEDTLS_CONFIG_BOARD_H | ||
|
||
#define MBEDTLS_ECP_NIST_OPTIM | ||
|
||
#include "ports/mimxrt/mbedtls/mbedtls_config.h" | ||
|
||
#endif /* MICROPY_INCLUDED_MBEDTLS_CONFIG_BOARD_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
/* | ||
* This file is part of the MicroPython project, http://micropython.org/ | ||
* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2023 Arduino SA | ||
* | ||
* 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. | ||
* | ||
* ESP-Hosted WiFi HAL. | ||
*/ | ||
|
||
#include "py/mphal.h" | ||
|
||
#if MICROPY_PY_NETWORK_ESP_HOSTED | ||
|
||
#include <stdint.h> | ||
#include <string.h> | ||
|
||
#include "py/runtime.h" | ||
#include "modmachine.h" | ||
#include "extmod/machine_spi.h" | ||
#include "mpconfigboard.h" | ||
|
||
#include "esp_hosted_hal.h" | ||
#include "esp_hosted_wifi.h" | ||
|
||
#ifndef MICROPY_HW_WIFI_IRQ | ||
#define MICROPY_HW_WIFI_IRQ MICROPY_HW_WIFI_HANDSHAKE | ||
#endif | ||
|
||
static mp_hal_pin_obj_t micropy_hw_esp_hosted_reset; | ||
static mp_hal_pin_obj_t micropy_hw_esp_hosted_gpio0; | ||
static mp_hal_pin_obj_t micropy_hw_wifi_dataready; | ||
static mp_hal_pin_obj_t micropy_hw_wifi_handshake; | ||
static mp_hal_pin_obj_t micropy_hw_wifi_spi_cs; | ||
static mp_hal_pin_obj_t micropy_hw_wifi_irq; | ||
|
||
|
||
STATIC mp_obj_t esp_hosted_pin_irq_callback(mp_obj_t self_in) { | ||
extern void mod_network_poll_events(void); | ||
mod_network_poll_events(); | ||
return mp_const_none; | ||
} | ||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_hosted_pin_irq_callback_obj, esp_hosted_pin_irq_callback); | ||
|
||
int esp_hosted_hal_init(uint32_t mode) { | ||
|
||
micropy_hw_wifi_dataready = MICROPY_HW_WIFI_DATAREADY; | ||
micropy_hw_wifi_handshake = MICROPY_HW_WIFI_HANDSHAKE; | ||
micropy_hw_wifi_irq = MICROPY_HW_WIFI_IRQ; | ||
micropy_hw_wifi_spi_cs = MICROPY_HW_WIFI_SPI_CS; | ||
micropy_hw_esp_hosted_reset = MICROPY_HW_ESP_HOSTED_RESET; | ||
micropy_hw_esp_hosted_gpio0 = MICROPY_HW_ESP_HOSTED_GPIO0; | ||
|
||
// Perform a hard reset and set pins to their defaults. | ||
esp_hosted_hal_deinit(); | ||
|
||
if (mode == ESP_HOSTED_MODE_BT) { | ||
// For Bluetooth mode, init is done. | ||
return 0; | ||
} | ||
|
||
mp_hal_pin_input(micropy_hw_wifi_handshake); | ||
mp_hal_pin_input(micropy_hw_wifi_dataready); | ||
|
||
// Enable Pin-IRQ for the handshake PIN to call esp_hosted_wifi_poll() | ||
mp_obj_t irq_trigger_attr[2]; | ||
mp_load_method_maybe((mp_obj_t)micropy_hw_wifi_irq, MP_QSTR_IRQ_RISING, irq_trigger_attr); | ||
|
||
if (irq_trigger_attr[0] != MP_OBJ_NULL && irq_trigger_attr[1] == MP_OBJ_NULL) { // value for IRQ rising found | ||
mp_obj_t pin_args[] = { | ||
NULL, // Method pointer | ||
(mp_obj_t)micropy_hw_wifi_irq, // Pin object | ||
(mp_obj_t)&esp_hosted_pin_irq_callback_obj, // Callback function object | ||
NULL, // The Rising edge value is set below. | ||
mp_const_true, // Hard IRQ, since the actual polling is scheduled. | ||
}; | ||
pin_args[3] = irq_trigger_attr[0]; | ||
mp_load_method_maybe((mp_obj_t)micropy_hw_wifi_irq, MP_QSTR_irq, pin_args); | ||
if (pin_args[0] != MP_OBJ_NULL && pin_args[1] != MP_OBJ_NULL) { | ||
mp_call_method_n_kw(3, 0, pin_args); | ||
} | ||
} | ||
|
||
// Initialize SPI. | ||
mp_obj_t spi_args[] = { | ||
MP_OBJ_NEW_SMALL_INT(MICROPY_HW_WIFI_SPI_ID), | ||
MP_OBJ_NEW_SMALL_INT(MICROPY_HW_WIFI_SPI_BAUDRATE), | ||
MP_OBJ_NEW_QSTR(MP_QSTR_polarity), MP_OBJ_NEW_SMALL_INT(1), | ||
}; | ||
|
||
MP_STATE_PORT(mp_wifi_spi) = | ||
MP_OBJ_TYPE_GET_SLOT(&machine_spi_type, make_new)((mp_obj_t)&machine_spi_type, 2, 1, spi_args); | ||
|
||
// SPI might change the direction/mode of CS pin, | ||
// set it to GPIO again just in case. | ||
mp_hal_pin_output(micropy_hw_wifi_spi_cs); | ||
mp_hal_pin_write(micropy_hw_wifi_spi_cs, 1); | ||
return 0; | ||
} | ||
|
||
int esp_hosted_hal_deinit(void) { | ||
|
||
// Disable Pin-IRQ for the handshake PIN | ||
mp_obj_t pin_args[] = { | ||
NULL, // Method pointer | ||
(mp_obj_t)micropy_hw_wifi_handshake, // Pin object | ||
mp_const_none // Set to None | ||
}; | ||
mp_load_method_maybe((mp_obj_t)micropy_hw_wifi_handshake, MP_QSTR_irq, pin_args); | ||
if (pin_args[0] && pin_args[1]) { | ||
mp_call_method_n_kw(1, 0, pin_args); | ||
} | ||
|
||
mp_hal_pin_output(micropy_hw_esp_hosted_reset); | ||
mp_hal_pin_output(micropy_hw_esp_hosted_gpio0); | ||
|
||
// mp_hal_pin_output(micropy_hw_wifi_spi_cs); | ||
// mp_hal_pin_write(micropy_hw_wifi_spi_cs, 1); | ||
|
||
// Perform a hard reset | ||
mp_hal_pin_write(micropy_hw_esp_hosted_gpio0, 1); | ||
mp_hal_pin_write(micropy_hw_esp_hosted_reset, 0); | ||
mp_hal_delay_ms(100); | ||
mp_hal_pin_write(micropy_hw_esp_hosted_reset, 1); | ||
mp_hal_delay_ms(500); | ||
|
||
MP_STATE_PORT(mp_wifi_spi) = MP_OBJ_NULL; | ||
return 0; | ||
} | ||
|
||
bool esp_hosted_hal_data_ready(void) { | ||
return mp_hal_pin_read(micropy_hw_wifi_dataready) && mp_hal_pin_read(micropy_hw_wifi_handshake); | ||
} | ||
|
||
int esp_hosted_hal_spi_transfer(const uint8_t *tx_buf, uint8_t *rx_buf, uint32_t size) { | ||
mp_obj_t mp_wifi_spi = MP_STATE_PORT(mp_wifi_spi); | ||
const mp_machine_spi_p_t *spi_proto = MP_OBJ_TYPE_GET_SLOT(&machine_spi_type, protocol); | ||
|
||
// Wait for handshake pin to go high. | ||
for (mp_uint_t start = mp_hal_ticks_ms(); ; mp_hal_delay_ms(1)) { | ||
if (mp_hal_pin_read(micropy_hw_wifi_handshake)) { | ||
break; | ||
} | ||
if ((mp_hal_ticks_ms() - start) >= 1000) { | ||
error_printf("timeout waiting for handshake\n"); | ||
return -1; | ||
} | ||
} | ||
|
||
mp_hal_pin_write(micropy_hw_wifi_spi_cs, 0); | ||
mp_hal_delay_ms(1); | ||
spi_proto->transfer(mp_wifi_spi, size, tx_buf, rx_buf); | ||
mp_hal_pin_write(micropy_hw_wifi_spi_cs, 1); | ||
return 0; | ||
} | ||
|
||
#endif // MICROPY_PY_NETWORK_NINAW10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.