@@ -56,9 +56,6 @@ static mrb_value
56
56
mrb_esp32_get_chip_model (mrb_state * mrb , mrb_value self ) {
57
57
esp_chip_info_t info ;
58
58
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
62
59
return mrb_fixnum_value (info .model );
63
60
}
64
61
@@ -79,6 +76,30 @@ mrb_mruby_esp32_system_gem_init(mrb_state* mrb) {
79
76
// ESP32::Timer
80
77
struct RClass * esp32_timer_module = mrb_define_module_under (mrb , esp32_module , "Timer" );
81
78
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 );
82
103
}
83
104
84
105
void
0 commit comments