diff --git a/mrbgems/machine-pwm/mrbgem.rake b/mrbgems/machine-pwm/mrbgem.rake new file mode 100644 index 0000000..8114ac0 --- /dev/null +++ b/mrbgems/machine-pwm/mrbgem.rake @@ -0,0 +1,5 @@ +MRuby::Gem::Specification.new('machine-pwm') do |spec| + spec.license = 'MIT' + spec.author = 'imi415' + spec.summary = 'PWM (Pulse Width Modulation) resource access' +end \ No newline at end of file diff --git a/mrbgems/machine-pwm/src/pwm.c b/mrbgems/machine-pwm/src/pwm.c new file mode 100644 index 0000000..1e1f0be --- /dev/null +++ b/mrbgems/machine-pwm/src/pwm.c @@ -0,0 +1,51 @@ +#include +#include +#include +#include +#include + +/* Private */ +#include "pwm.h" + +typedef struct { + uint32_t channel; +} mrb_pwm_t; + +static void mrb_pwm_free(mrb_state *mrb, void *ptr); + +const struct mrb_data_type mrb_pwm_type = { + .struct_name = "PWM", + .dfree = mrb_pwm_free, +}; + +static void mrb_pwm_free(mrb_state *mrb, void *ptr) { + mrb_free(mrb, ptr); +} + +static mrb_value mrb_pwm_initialize(mrb_state *mrb, mrb_value self) { + /* TODO: Implement this */ + return self; +} + +void mrb_machine_pwm_gem_init(mrb_state *mrb) { + /** + * Example: + * pwm_pin led = Machine::PWM.new(0, {frequency: 1000, duty: 32768, enable: false}) + * led.enable + * led.freq(5000) + * led.duty(10) + */ + + struct RClass *module_machine = mrb_define_module(mrb, "Machine"); + struct RClass *class_pwm = mrb_define_class_under(mrb, module_machine, "PWM", mrb->object_class); + + MRB_SET_INSTANCE_TT(class_pwm, MRB_TT_CDATA); + + mrb_define_method(mrb, class_pwm, "initialize", mrb_pwm_initialize, MRB_ARGS_ARG(1, 1)); + + /* TODO: Implement methods */ +} + +void mrb_machine_gpio_gem_final(mrb_state *mrb) { + /* Unused */ +} \ No newline at end of file diff --git a/mrbgems/machine-pwm/src/pwm.h b/mrbgems/machine-pwm/src/pwm.h new file mode 100644 index 0000000..1d89027 --- /dev/null +++ b/mrbgems/machine-pwm/src/pwm.h @@ -0,0 +1,12 @@ +#ifndef MRBGEMS_MACHINE_PWM_PWM_H +#define MRBGEMS_MACHINE_PWM_PWM_H + +#include +#include + +int mrb_machine_pwm_impl_config(uint32_t pin); +int mrb_machine_pwm_impl_output_set(uint32_t pin, bool enable); +int mrb_machine_pwm_impl_freq_set(uint32_t pin, uint32_t freq); +int mrb_machine_pwm_impl_duty_set(uint32_t pin, uint16_t duty); + +#endif // MRBGEMS_MACHINE_PWM_PWM_H diff --git a/mrbgems/machine.gembox b/mrbgems/machine.gembox index aaf93d9..9b11c23 100644 --- a/mrbgems/machine.gembox +++ b/mrbgems/machine.gembox @@ -2,4 +2,5 @@ MRuby::GemBox.new do |conf| conf.gem :core => "../../mrbgems/machine-adc" conf.gem :core => "../../mrbgems/machine-devmem" conf.gem :core => "../../mrbgems/machine-gpio" + conf.gem :core => "../../mrbgems/machine-pwm" end \ No newline at end of file