Skip to content

Commit 638a967

Browse files
committed
adds spi3wire as a user c module/
1 parent f1e7696 commit 638a967

File tree

9 files changed

+747
-3
lines changed

9 files changed

+747
-3
lines changed

api_drivers/common_api_drivers/frozen/other/spi3wire.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2+
# ******* NOTICE ********
3+
# This module is no longer used.
4+
5+
16
from micropython import const # NOQA
27
import machine # NOQA
38

builder/esp32.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,8 @@ def build_manifest(
682682

683683
set_displays.extend(generate_manifest(
684684
script_dir, lvgl_api, manifest_path,
685-
displays, indevs, expanders, frozen_manifest,
686-
f'{script_dir}/api_drivers/common_api_drivers/frozen/other/spi3wire.py'
685+
displays, indevs, expanders, frozen_manifest
686+
# f'{script_dir}/api_drivers/common_api_drivers/frozen/other/spi3wire.py'
687687
))
688688

689689

@@ -1213,7 +1213,8 @@ def update_main():
12131213
'',
12141214
'#include "../../../../ext_mod/lcd_bus/esp32_include/spi_bus.h"',
12151215
'#include "../../../../ext_mod/lcd_bus/esp32_include/i2c_bus.h"',
1216-
'#include "../../../../micropy_updates/common/mp_spi_common.h"'
1216+
'#include "../../../../ext_mod/spi3wire/include/spi3wire.h"',
1217+
'#include "../../../../micropy_updates/common/mp_spi_common.h"',
12171218
'',
12181219
'#if MICROPY_BLUETOOTH_NIMBLE'
12191220
]
@@ -1239,6 +1240,8 @@ def update_main():
12391240
' ',
12401241
' mp_lcd_i2c_bus_deinit_all();',
12411242
' ',
1243+
' mp_spi3wire_deinit_all();',
1244+
' ',
12421245
' machine_hw_spi_bus_deinit_all();'
12431246
]
12441247

ext_mod/micropython.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
if(ESP_PLATFORM)
22
include(${CMAKE_CURRENT_LIST_DIR}/esp32_components.cmake)
3+
include(${CMAKE_CURRENT_LIST_DIR}/spi3wire/micropython.cmake)
34
endif(ESP_PLATFORM)
45

56
include(${CMAKE_CURRENT_LIST_DIR}/lcd_bus/micropython.cmake)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
#include <stdint.h>
10+
11+
#include "esp_lcd_types.h"
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
// Maximum SPI clock speed
18+
#define PANEL_IO_3WIRE_SPI_CLK_MAX (500 * 1000UL)
19+
20+
/**
21+
* @brief SPI line configuration structure
22+
*/
23+
typedef struct {
24+
int cs_gpio_num; /*!< GPIO used for CS line */
25+
int scl_gpio_num; /*!< GPIO used for SCL line */
26+
int sda_gpio_num; /*!< GPIO used for SDA line */
27+
} spi_line_config_t;
28+
29+
/**
30+
* @brief Panel IO configuration structure
31+
*/
32+
33+
typedef struct {
34+
spi_line_config_t line_config; /*!< SPI line configuration */
35+
uint32_t expect_clk_speed; /*!< Expected SPI clock speed, in Hz (1 ~ 500000
36+
* If this value is 0, it will be set to `PANEL_IO_3WIRE_SPI_CLK_MAX` by default
37+
* The actual frequency may be very different due to the limitation of the software delay */
38+
uint32_t spi_mode: 2; /*!< Traditional SPI mode (0 ~ 3) */
39+
uint32_t lcd_cmd_bytes: 3; /*!< Bytes of LCD command (1 ~ 4) */
40+
uint32_t lcd_param_bytes: 3; /*!< Bytes of LCD parameter (1 ~ 4) */
41+
struct {
42+
uint32_t use_dc_bit: 1; /*!< If this flag is enabled, transmit DC bit at the beginning of every command and data */
43+
uint32_t dc_zero_on_data: 1; /*!< If this flag is enabled, DC bit = 0 means transfer data, DC bit = 1 means transfer command */
44+
uint32_t lsb_first: 1; /*!< If this flag is enabled, transmit LSB bit first */
45+
uint32_t cs_high_active: 1; /*!< If this flag is enabled, CS line is high active */
46+
uint32_t del_keep_cs_inactive: 1; /*!< If this flag is enabled, keep CS line inactive even if panel_io is deleted */
47+
} flags;
48+
} esp_lcd_panel_io_3wire_spi_config_t;
49+
50+
/**
51+
* @brief Create a new panel IO instance for 3-wire SPI interface (simulate by software)
52+
*
53+
* @note This function uses GPIO or IO expander to simulate SPI interface by software and just supports to write data.
54+
* It is only suitable for some applications with low speed SPI interface. (Such as initializing RGB panel)
55+
*
56+
* @param[in] io_config Panel IO configuration
57+
* @param[out] ret_io Pointer to return the created panel IO instance
58+
* @return
59+
* - ESP_OK: Success
60+
* - ESP_ERR_INVALID_ARG: Invalid argument
61+
* - ESP_ERR_NO_MEM: Failed to allocate memory for panel IO instance
62+
* - Others: Fail
63+
*/
64+
esp_err_t esp_lcd_new_panel_io_3wire_spi(const esp_lcd_panel_io_3wire_spi_config_t *io_config, esp_lcd_panel_io_handle_t *ret_io);
65+
66+
#ifdef __cplusplus
67+
}
68+
#endif

ext_mod/spi3wire/include/spi3wire.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
3+
#ifndef __SPI3WIRE_H__
4+
#define __SPI3WIRE_H__
5+
6+
// micropython includes
7+
#include "mphalport.h"
8+
#include "py/obj.h"
9+
10+
#include "esp_lcd_panel_io_additions.h"
11+
#include "esp_lcd_panel_io.h"
12+
13+
14+
typedef struct {
15+
mp_obj_base_t base;
16+
17+
esp_lcd_panel_io_handle_t panel_io_handle;
18+
esp_lcd_panel_io_3wire_spi_config_t *io_config;
19+
} mp_spi3wire_obj_t;
20+
21+
extern const mp_obj_type_t mp_spi3wire_type;
22+
23+
extern void mp_spi3wire_deinit_all(void);
24+
25+
#endif

ext_mod/spi3wire/micropython.cmake

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Create an INTERFACE library for our C module.
2+
add_library(usermod_spi3wire INTERFACE)
3+
4+
set(SPI3WIRE_INCLUDES
5+
${CMAKE_CURRENT_LIST_DIR}
6+
${CMAKE_CURRENT_LIST_DIR}/include
7+
)
8+
9+
set(SPI3WIRE_SOURCES
10+
${CMAKE_CURRENT_LIST_DIR}/src/spi3wire.c
11+
${CMAKE_CURRENT_LIST_DIR}/src/esp_lcd_panel_io_3wire_spi.c
12+
)
13+
14+
15+
# Add our source files to the lib
16+
target_sources(usermod_spi3wire INTERFACE ${SPI3WIRE_SOURCES})
17+
18+
# Add include directories.
19+
target_include_directories(usermod_spi3wire INTERFACE ${SPI3WIRE_INCLUDES})
20+
21+
# Link our INTERFACE library to the usermod target.
22+
target_link_libraries(usermod INTERFACE usermod_spi3wire)

0 commit comments

Comments
 (0)