Skip to content

Commit

Permalink
Make sure that PWM doesn't glitch when changing duty-cycle or period.…
Browse files Browse the repository at this point in the history
… Update music module to use PWM.
  • Loading branch information
markshannon committed Sep 20, 2016
1 parent b586a0c commit ecbb1c5
Show file tree
Hide file tree
Showing 13 changed files with 398 additions and 233 deletions.
5 changes: 5 additions & 0 deletions inc/genhdr/qstrdefs.generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ QDEF(MP_QSTR_pin15, (const byte*)"\x56\x05" "pin15")
QDEF(MP_QSTR_pin16, (const byte*)"\x55\x05" "pin16")
QDEF(MP_QSTR_pin19, (const byte*)"\x5a\x05" "pin19")
QDEF(MP_QSTR_pin20, (const byte*)"\x30\x05" "pin20")
QDEF(MP_QSTR_get_pull, (const byte*)"\x49\x08" "get_pull")
QDEF(MP_QSTR_set_pull, (const byte*)"\xdd\x08" "set_pull")
QDEF(MP_QSTR_PULL_UP, (const byte*)"\xba\x07" "PULL_UP")
QDEF(MP_QSTR_PULL_DOWN, (const byte*)"\xad\x09" "PULL_DOWN")
QDEF(MP_QSTR_NO_PULL, (const byte*)"\x1e\x07" "NO_PULL")
QDEF(MP_QSTR_MicroBitImage, (const byte*)"\x87\x0d" "MicroBitImage")
QDEF(MP_QSTR_Image, (const byte*)"\x62\x05" "Image")
QDEF(MP_QSTR_image, (const byte*)"\x42\x05" "image")
Expand Down
5 changes: 2 additions & 3 deletions inc/lib/pwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
void pwm_start(void);
void pwm_stop(void);

int32_t pwm_set_period_us(int32_t us);
int pwm_set_period_us(int32_t us);
int32_t pwm_get_period_us(void);
int pwm_set_duty_cycle(int32_t pin, int32_t value);
void pwm_release_pin(PinName pin);
void pwm_set_duty_cycle(int32_t pin, int32_t value);

#endif // __MICROPY_INCLUDED_LIB_PWM_H__
4 changes: 3 additions & 1 deletion inc/microbit/microbitobj.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ typedef struct _microbit_pin_obj_t {
PinName name; // The pin number in the GPIO port.
} microbit_pin_obj_t;

microbit_pin_obj_t *microbit_obj_get_pin(mp_obj_t o);
const microbit_pin_obj_t *microbit_obj_get_pin(mp_obj_t o);
PinName microbit_obj_get_pin_name(mp_obj_t o);

extern volatile bool compass_up_to_date;
Expand All @@ -46,6 +46,8 @@ extern volatile bool compass_updating;
extern volatile bool accelerometer_up_to_date;
extern volatile bool accelerometer_updating;

extern void microbit_pin_init(void);

}

#endif // __MICROPY_INCLUDED_MICROBIT_MICROBITOBJ_H__
15 changes: 9 additions & 6 deletions inc/microbit/microbitpin.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,10 @@
mp_obj_t microbit_pin_write_digital(mp_obj_t self_in, mp_obj_t value_in);
mp_obj_t microbit_pin_read_digital(mp_obj_t self_in);

typedef void (*release_funcptr)(PinName pin);

typedef struct _pinmode {
qstr name;
bool acquireable;
bool allows_digital_read;
release_funcptr release;
bool acquireable; /* Can the pin be acquired from this state? */
bool allows_digital_read; /* Is this state compatible with performing a digital read on this pin? */
} microbit_pinmode_t;

#define PINMODE_INDEX_UNUSED 0
Expand All @@ -60,6 +57,7 @@ typedef struct _pinmode {
#define PINMODE_INDEX_I2C 7
#define PINMODE_INDEX_SPI 8
#define PINMODE_INDEX_3V 9
#define PINMODE_INDEX_MUSIC 10

void microbit_obj_pin_set_mode(const microbit_pin_obj_t *pin, uint8_t new_mode);

Expand All @@ -69,6 +67,11 @@ void microbit_obj_pin_acquire(const microbit_pin_obj_t *pin, uint8_t new_mode);

bool microbit_obj_pin_mode_allows_digital_read(const microbit_pin_obj_t *pin);

bool microbit_pin_debounced(PinName name);
bool microbit_pin_high_debounced(microbit_pin_obj_t *pin);

uint8_t microbit_obj_pin_get_mode(const microbit_pin_obj_t *pin);

bool microbit_obj_pin_can_be_acquired(const microbit_pin_obj_t *pin);


#endif // __MICROPY_INCLUDED_MICROBIT_MICROBITPIN_H__
1 change: 0 additions & 1 deletion inc/microbit/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ extern const struct _mp_obj_module_t speech_module;
void *async_data[2]; \
void *async_music_data; \
uint8_t *radio_buf; \
void *pwm_next_event; \
void *audio_buffer; \
void *audio_source; \
void *speech_data;
Expand Down
6 changes: 5 additions & 1 deletion inc/microbit/qstrdefsport.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ Q(pin15)
Q(pin16)
Q(pin19)
Q(pin20)
Q(get_pull)
Q(set_pull)
Q(PULL_UP)
Q(PULL_DOWN)
Q(NO_PULL)

Q(MicroBitImage)
Q(Image)
Expand Down Expand Up @@ -452,7 +457,6 @@ Q(RATE_1MBIT)
Q(RATE_2MBIT)

Q(unused)
^
Q(analog)
Q(digital)
Q(button)
Expand Down

0 comments on commit ecbb1c5

Please sign in to comment.