Skip to content

Commit ecc50df

Browse files
committed
Add mruby constants for chip models
These will require ESP-IDF 5.1 or higher to comile
1 parent e20c6da commit ecc50df

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/mrb_esp32_system.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ static mrb_value
5656
mrb_esp32_get_chip_model(mrb_state *mrb, mrb_value self) {
5757
esp_chip_info_t info;
5858
esp_chip_info(&info);
59-
60-
// The integer value in info.model is one of an enum, esp_chip_model_t, found here:
61-
// https://github.com/espressif/esp-idf/blob/master/components/esp_hw_support/include/esp_chip_info.h
6259
return mrb_fixnum_value(info.model);
6360
}
6461

@@ -79,6 +76,30 @@ mrb_mruby_esp32_system_gem_init(mrb_state* mrb) {
7976
// ESP32::Timer
8077
struct RClass *esp32_timer_module = mrb_define_module_under(mrb, esp32_module, "Timer");
8178
mrb_define_module_function(mrb, esp32_timer_module, "get_time", mrb_esp32_esp_timer_get_time, MRB_ARGS_NONE());
79+
80+
// ESP32::Constants
81+
struct RClass *constants = mrb_define_module_under(mrb, esp32_module, "Constants");
82+
83+
// Pass a C constant through to mruby, defined inside ESP32::Constants.
84+
#define define_const(SYM) \
85+
do { \
86+
mrb_define_const(mrb, constants, #SYM, mrb_fixnum_value(SYM)); \
87+
} while (0)
88+
89+
//
90+
// ESP32::System.chip_model returns a constant from the esp_chip_model_t enum:
91+
// https://github.com/espressif/esp-idf/blob/master/components/esp_hw_support/include/esp_chip_info.h
92+
//
93+
// Define constants from the enum in mruby:
94+
define_const(CHIP_ESP32);
95+
define_const(CHIP_ESP32S2);
96+
define_const(CHIP_ESP32S3);
97+
define_const(CHIP_ESP32C3);
98+
define_const(CHIP_ESP32C2);
99+
define_const(CHIP_ESP32C6);
100+
define_const(CHIP_ESP32H2);
101+
// define_const(CHIP_ESP32P4);
102+
define_const(CHIP_POSIX_LINUX);
82103
}
83104

84105
void

0 commit comments

Comments
 (0)