├── .gitignore ├── Cargo.toml ├── README.md ├── esp32-sys ├── Cargo.toml └── src │ ├── bindings.h │ └── lib.rs └── src └── main.rs /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | build/ 3 | Cargo.lock 4 | 5 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "esp-app" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | [dependencies] 7 | esp32-sys = { path = "esp32-sys" } 8 | 9 | [profile.dev] 10 | lto = false 11 | incremental = false 12 | debug = false # debug adds frame pointers - which must be omitted 13 | codegen-units = 1 14 | 15 | [profile.release] 16 | lto = false 17 | incremental = false 18 | debug = false # debug adds frame pointers - which must be omitted 19 | codegen-units = 1 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rust ESP32 project template 2 | 3 | This is a project template for the use of [ctron/rust-esp-container](https://github.com/ctron/rust-esp-container). 4 | 5 | 6 | -------------------------------------------------------------------------------- /esp32-sys/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "esp32-sys" 3 | version = "0.1.0" 4 | edition = "2015" 5 | 6 | [dependencies] 7 | -------------------------------------------------------------------------------- /esp32-sys/src/bindings.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | -------------------------------------------------------------------------------- /esp32-sys/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | #![allow(non_upper_case_globals)] 3 | #![allow(non_camel_case_types)] 4 | #![allow(non_snake_case)] 5 | 6 | pub mod std { 7 | pub use core::*; 8 | pub mod os { 9 | pub mod raw { 10 | pub enum c_void {} 11 | pub type c_uchar = u8; 12 | pub type c_schar = i8; 13 | pub type c_char = i8; 14 | pub type c_short = i16; 15 | pub type c_ushort = u16; 16 | pub type c_int = i32; 17 | pub type c_uint = u32; 18 | pub type c_long = i32; 19 | pub type c_ulong = u32; 20 | pub type c_longlong = i64; 21 | pub type c_ulonglong = u64; 22 | } 23 | } 24 | } 25 | 26 | include!("bindings.rs"); 27 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | #![no_main] 3 | 4 | extern crate esp32_sys; 5 | 6 | use core::panic::PanicInfo; 7 | use core::ptr; 8 | use esp32_sys::*; 9 | 10 | #[panic_handler] 11 | fn panic(_info: &PanicInfo) -> ! { 12 | loop {} 13 | } 14 | 15 | const BLINK_GPIO: gpio_num_t = gpio_num_t_GPIO_NUM_2; 16 | const UART_NUM: uart_port_t = uart_port_t_UART_NUM_1; 17 | //const ECHO_TEST_TXD: i32 = gpio_num_t_GPIO_NUM_17 as i32; 18 | //const ECHO_TEST_RXD: i32 = gpio_num_t_GPIO_NUM_16 as i32; 19 | const ECHO_TEST_TXD: i32 = gpio_num_t_GPIO_NUM_1 as i32; 20 | const ECHO_TEST_RXD: i32 = gpio_num_t_GPIO_NUM_3 as i32; 21 | const ECHO_TEST_RTS: i32 = UART_PIN_NO_CHANGE; 22 | const ECHO_TEST_CTS: i32 = UART_PIN_NO_CHANGE; 23 | 24 | const BUF_SIZE: i32 = 1024; 25 | 26 | #[no_mangle] 27 | pub fn app_main() { 28 | unsafe { 29 | rust_blink_and_write(); 30 | } 31 | } 32 | 33 | unsafe fn rust_blink_and_write() { 34 | gpio_pad_select_gpio(BLINK_GPIO as u8); 35 | 36 | /* Set the GPIO as a push/pull output */ 37 | gpio_set_direction(BLINK_GPIO, gpio_mode_t_GPIO_MODE_OUTPUT); 38 | 39 | /* Configure parameters of an UART driver, 40 | * communication pins and install the driver */ 41 | let uart_config = uart_config_t { 42 | baud_rate: 115200, 43 | data_bits: uart_word_length_t_UART_DATA_8_BITS, 44 | parity: uart_parity_t_UART_PARITY_DISABLE, 45 | stop_bits: uart_stop_bits_t_UART_STOP_BITS_1, 46 | flow_ctrl: uart_hw_flowcontrol_t_UART_HW_FLOWCTRL_DISABLE, 47 | rx_flow_ctrl_thresh: 0, 48 | use_ref_tick: false, 49 | }; 50 | 51 | uart_param_config(UART_NUM, &uart_config); 52 | uart_set_pin(UART_NUM, ECHO_TEST_TXD, ECHO_TEST_RXD, ECHO_TEST_RTS, ECHO_TEST_CTS); 53 | uart_driver_install(UART_NUM, BUF_SIZE * 2, 0, 0, ptr::null_mut(), 0); 54 | 55 | loop { 56 | 57 | /* Blink off (output low) */ 58 | gpio_set_level(BLINK_GPIO, 0); 59 | 60 | //vTaskDelay(1000 / portTICK_PERIOD_MS); 61 | ets_delay_us(1_000_000); 62 | 63 | // Write data to UART. 64 | let test_str = "This is a test string.\n"; 65 | uart_write_bytes(UART_NUM, test_str.as_ptr() as *const _, test_str.len()); 66 | 67 | /* Blink on (output high) */ 68 | gpio_set_level(BLINK_GPIO, 1); 69 | 70 | // vTaskDelay(1000 / portTICK_PERIOD_MS); 71 | ets_delay_us(1_000_000); 72 | } 73 | } 74 | 75 | --------------------------------------------------------------------------------