Initial PWM gem.
Signed-off-by: Yilin Sun <imi415@imi.moe>
This commit is contained in:
parent
309be9522b
commit
1c6b50af4e
|
@ -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
|
|
@ -0,0 +1,51 @@
|
|||
#include <mruby.h>
|
||||
#include <mruby/class.h>
|
||||
#include <mruby/data.h>
|
||||
#include <mruby/hash.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/* 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 */
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef MRBGEMS_MACHINE_PWM_PWM_H
|
||||
#define MRBGEMS_MACHINE_PWM_PWM_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
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
|
|
@ -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
|
Loading…
Reference in New Issue