Skip to content

Commit 7e57fa8

Browse files
authored
Merge pull request #9231 from gitcnd/add-board-ai-thinker-esp32-cam
Add support for Ai Thinker ESP32-CAM boards
2 parents 3178d38 + 24f2e4f commit 7e57fa8

File tree

5 files changed

+222
-0
lines changed

5 files changed

+222
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2024 Chris Drake, independently providing these changes.
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "supervisor/board.h"
28+
29+
#include "mpconfigboard.h"
30+
#include "shared-bindings/microcontroller/Pin.h"
31+
#include "components/driver/gpio/include/driver/gpio.h"
32+
#include "components/hal/include/hal/gpio_hal.h"
33+
#include "common-hal/microcontroller/Pin.h"
34+
35+
void board_init(void) {
36+
reset_board();
37+
}
38+
39+
bool espressif_board_reset_pin_number(gpio_num_t pin_number) {
40+
// Pull one LED down on reset rather than the default up
41+
if (pin_number == 4) { // This is the flashlight LED - very bright
42+
gpio_config_t cfg = {
43+
.pin_bit_mask = BIT64(pin_number),
44+
.mode = GPIO_MODE_DISABLE,
45+
.pull_up_en = false,
46+
.pull_down_en = true,
47+
.intr_type = GPIO_INTR_DISABLE,
48+
};
49+
gpio_config(&cfg);
50+
return true;
51+
}
52+
return false;
53+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2024 Chris Drake, independently providing these changes.
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#define MICROPY_HW_BOARD_NAME "Ai Thinker ESP32-CAM"
28+
#define MICROPY_HW_MCU_NAME "ESP32"
29+
30+
#define MICROPY_HW_LED_STATUS (&pin_GPIO33)
31+
#define MICROPY_HW_LED_STATUS_INVERTED (1)
32+
33+
34+
#define CIRCUITPY_BOARD_I2C (2)
35+
/* OV2640 camera I2C pins are GPIO27 and _GPIO26. GPIO12 and GPIO13 are unused unless SD card inserted:- */
36+
#define CIRCUITPY_BOARD_I2C_PIN { {.scl = &pin_GPIO27, .sda = &pin_GPIO26}, \
37+
{.scl = &pin_GPIO12, .sda = &pin_GPIO13} }
38+
39+
// SD_CARD
40+
#define DEFAULT_SPI_BUS_SCK (&pin_GPIO14)
41+
#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO15)
42+
#define DEFAULT_SPI_BUS_MISO (&pin_GPIO2)
43+
44+
// UART pins attached to the USB-serial converter chip
45+
#define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO1)
46+
#define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO3)
47+
48+
#define CIRCUITPY_I2C_ALLOW_INTERNAL_PULL_UP (1)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
CIRCUITPY_CREATOR_ID = 0x000C303B
2+
CIRCUITPY_CREATION_ID = 0x00320001
3+
4+
IDF_TARGET = esp32
5+
6+
# This board doesn't have USB by default, it
7+
# instead uses a CH340C USB-to-Serial chip
8+
CIRCUITPY_USB_DEVICE = 0
9+
CIRCUITPY_ESP_USB_SERIAL_JTAG = 0
10+
11+
CIRCUITPY_ESP_FLASH_MODE = qio
12+
CIRCUITPY_ESP_FLASH_FREQ = 80m
13+
CIRCUITPY_ESP_FLASH_SIZE = 4MB
14+
15+
CIRCUITPY_ESP_PSRAM_SIZE = 8MB
16+
CIRCUITPY_ESP_PSRAM_MODE = qio
17+
CIRCUITPY_ESP_PSRAM_FREQ = 80m
18+
19+
CIRCUITPY_ESPCAMERA = 1
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#include "py/objtuple.h"
2+
#include "shared-bindings/board/__init__.h"
3+
4+
CIRCUITPY_BOARD_BUS_SINGLETON(sscb_i2c, i2c, 2) // Camera sensor
5+
6+
STATIC const mp_rom_obj_tuple_t camera_data_tuple = {
7+
// The order matters. They must be ordered from low to high (Y2, Y3 .. Y9). Do not include any of the control pins in here.
8+
{&mp_type_tuple},
9+
8,
10+
{
11+
MP_ROM_PTR(&pin_GPIO5), // Y2
12+
MP_ROM_PTR(&pin_GPIO18), // Y3
13+
MP_ROM_PTR(&pin_GPIO19), // Y4
14+
MP_ROM_PTR(&pin_GPIO21), // Y5
15+
MP_ROM_PTR(&pin_GPIO36), // Y6
16+
MP_ROM_PTR(&pin_GPIO39), // Y7
17+
MP_ROM_PTR(&pin_GPIO34), // Y8
18+
MP_ROM_PTR(&pin_GPIO35) // Y9
19+
}
20+
};
21+
22+
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
23+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
24+
25+
// Red LED on the back of the board
26+
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO33) },
27+
{ MP_ROM_QSTR(MP_QSTR_LED_INVERTED), MP_ROM_PTR(&pin_GPIO33) },
28+
29+
// Bright white LED flashlight on the front (be aware that the SD card uses this when in fast mode)
30+
{ MP_ROM_QSTR(MP_QSTR_FLASHLIGHT), MP_ROM_PTR(&pin_GPIO4) },
31+
32+
// The second ESP32-CAM-MB button (first is RST)
33+
{ MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO0) },
34+
35+
// SD Card (fast mode aka SDMMC)
36+
{ MP_ROM_QSTR(MP_QSTR_SDIO_CLK), MP_ROM_PTR(&pin_GPIO14)},
37+
{ MP_ROM_QSTR(MP_QSTR_SDIO_CMD), MP_ROM_PTR(&pin_GPIO15)},
38+
{ MP_ROM_QSTR(MP_QSTR_SDIO_D0), MP_ROM_PTR(&pin_GPIO2)},
39+
{ MP_ROM_QSTR(MP_QSTR_SDIO_D1), MP_ROM_PTR(&pin_GPIO4)},
40+
{ MP_ROM_QSTR(MP_QSTR_SDIO_D2), MP_ROM_PTR(&pin_GPIO12)},
41+
{ MP_ROM_QSTR(MP_QSTR_SDIO_D3), MP_ROM_PTR(&pin_GPIO13)},
42+
43+
// SD Card (slow mode)
44+
{ MP_ROM_QSTR(MP_QSTR_SD_SCK), MP_ROM_PTR(&pin_GPIO14)},
45+
{ MP_ROM_QSTR(MP_QSTR_SD_MOSI), MP_ROM_PTR(&pin_GPIO15)},
46+
{ MP_ROM_QSTR(MP_QSTR_SD_MISO), MP_ROM_PTR(&pin_GPIO2)},
47+
{ MP_ROM_QSTR(MP_QSTR_SD_CS), MP_ROM_PTR(&pin_GPIO13)},
48+
{ MP_ROM_QSTR(MP_QSTR_SD_SPI), MP_ROM_PTR(&board_spi_obj) },
49+
50+
// Camera data
51+
{ MP_ROM_QSTR(MP_QSTR_CAMERA_DATA), MP_ROM_PTR(&camera_data_tuple) },
52+
{ MP_ROM_QSTR(MP_QSTR_CAMERA_DATA2), MP_ROM_PTR(&pin_GPIO5) },
53+
{ MP_ROM_QSTR(MP_QSTR_CAMERA_DATA3), MP_ROM_PTR(&pin_GPIO18) },
54+
{ MP_ROM_QSTR(MP_QSTR_CAMERA_DATA4), MP_ROM_PTR(&pin_GPIO19) },
55+
{ MP_ROM_QSTR(MP_QSTR_CAMERA_DATA5), MP_ROM_PTR(&pin_GPIO21) },
56+
{ MP_ROM_QSTR(MP_QSTR_CAMERA_DATA6), MP_ROM_PTR(&pin_GPIO36) },
57+
{ MP_ROM_QSTR(MP_QSTR_CAMERA_DATA7), MP_ROM_PTR(&pin_GPIO39) },
58+
{ MP_ROM_QSTR(MP_QSTR_CAMERA_DATA8), MP_ROM_PTR(&pin_GPIO34) },
59+
{ MP_ROM_QSTR(MP_QSTR_CAMERA_DATA9), MP_ROM_PTR(&pin_GPIO35) },
60+
61+
{ MP_ROM_QSTR(MP_QSTR_CAMERA_HREF), MP_ROM_PTR(&pin_GPIO23) },
62+
{ MP_ROM_QSTR(MP_QSTR_CAMERA_PCLK), MP_ROM_PTR(&pin_GPIO22) },
63+
{ MP_ROM_QSTR(MP_QSTR_CAMERA_PWDN), MP_ROM_PTR(&pin_GPIO32) },
64+
{ MP_ROM_QSTR(MP_QSTR_CAMERA_RESET), NULL },
65+
{ MP_ROM_QSTR(MP_QSTR_CAMERA_VSYNC), MP_ROM_PTR(&pin_GPIO25) },
66+
{ MP_ROM_QSTR(MP_QSTR_CAMERA_XCLK), MP_ROM_PTR(&pin_GPIO0) },
67+
68+
{ MP_ROM_QSTR(MP_QSTR_CAMERA_SIOD), MP_ROM_PTR(&pin_GPIO26) }, // SDA
69+
{ MP_ROM_QSTR(MP_QSTR_CAMERA_SIOC), MP_ROM_PTR(&pin_GPIO27) }, // SCL
70+
71+
{ MP_ROM_QSTR(MP_QSTR_U0R), MP_ROM_PTR(&pin_GPIO3) },
72+
{ MP_ROM_QSTR(MP_QSTR_U0T), MP_ROM_PTR(&pin_GPIO1) },
73+
74+
{ MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) }, // the button
75+
{ MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_GPIO1) },
76+
{ MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) },
77+
{ MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) },
78+
79+
{ MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) },
80+
{ MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) },
81+
82+
{ MP_ROM_QSTR(MP_QSTR_IO12), MP_ROM_PTR(&pin_GPIO12) },
83+
{ MP_ROM_QSTR(MP_QSTR_IO13), MP_ROM_PTR(&pin_GPIO13) },
84+
{ MP_ROM_QSTR(MP_QSTR_IO14), MP_ROM_PTR(&pin_GPIO14) },
85+
{ MP_ROM_QSTR(MP_QSTR_IO15), MP_ROM_PTR(&pin_GPIO15) },
86+
87+
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO4) },
88+
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO13) },
89+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }
90+
91+
};
92+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# Espressif IoT Development Framework Configuration
3+
#
4+
#
5+
#
6+
# Component config
7+
#
8+
#
9+
# Hardware Settings
10+
CONFIG_OV2640_SUPPORT=y

0 commit comments

Comments
 (0)