1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-24 19:42:27 +03:00

Timer0 and Servo library support

This exposes the Timer0
This provides a Servo library support compatible with Arduino Servo
library but only supports the two timers the esp8266 has available
This commit is contained in:
Makuna
2015-05-29 13:30:15 -07:00
parent bca0997046
commit 3c3bc0f523
9 changed files with 727 additions and 7 deletions

View File

@ -20,22 +20,33 @@
*/
#include "wiring_private.h"
#include "pins_arduino.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "c_types.h"
#include "ets_sys.h"
void (*timer1_user_cb)(void);
#ifdef __cplusplus
}
#endif
/ ------------------------------------------------------------------ -
// timer 1
static volatile timercallback timer1_user_cb = NULL;
void timer1_isr_handler(void *para){
if((T1C & ((1 << TCAR) | (1 << TCIT))) == 0) TEIE &= ~TEIE1;//edge int disable
if ((T1C & ((1 << TCAR) | (1 << TCIT))) == 0) TEIE &= ~TEIE1;//edge int disable
T1I = 0;
if(timer1_user_cb) timer1_user_cb();
if (timer1_user_cb) timer1_user_cb();
}
void timer1_isr_init(){
ETS_FRC_TIMER1_INTR_ATTACH(timer1_isr_handler, NULL);
}
void timer1_attachInterrupt(void (*userFunc)(void)) {
void timer1_attachInterrupt(timercallback userFunc) {
timer1_user_cb = userFunc;
ETS_FRC1_INTR_ENABLE();
}
@ -52,11 +63,39 @@ void timer1_enable(uint8_t divider, uint8_t int_type, uint8_t reload){
}
void timer1_write(uint32_t ticks){
T1L = ((ticks) & 0x7FFFFF);
if((T1C & (1 << TCIT)) == 0) TEIE |= TEIE1;//edge int enable
T1L = ((ticks)& 0x7FFFFF);
if ((T1C & (1 << TCIT)) == 0) TEIE |= TEIE1;//edge int enable
}
void timer1_disable(){
T1C = 0;
T1I = 0;
}
//-------------------------------------------------------------------
// timer 0
static volatile timercallback timer0_user_cb = NULL;
void timer0_isr_handler(void* para){
if (timer0_user_cb) {
timer0_user_cb();
}
}
void timer0_isr_init(){
ETS_CCOMPARE0_INTR_ATTACH(timer0_isr_handler, NULL);
}
void timer0_attachInterrupt(timercallback userFunc) {
timer0_user_cb = userFunc;
ETS_CCOMPARE0_ENABLE();
}
void timer0_detachInterrupt() {
timer0_user_cb = NULL;
ETS_CCOMPARE0_DISABLE();
}