Exemplo n.º 1
0
static inline ICACHE_RAM_ATTR void ReloadTimer(uint32_t a) {
  // Below a threshold you actually miss the edge IRQ, so ensure enough time
  if (a > 32) {
    timer1_write(a);
  } else {
    timer1_write(32);
  }
}
Exemplo n.º 2
0
// frequency (in hertz) and duration (in milliseconds).
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration) {
  _pin = esp8266_pinToGpio[_pin];
  int8_t _index;

  _index = toneBegin(_pin);

  if (_index >= 0) {
    // Set the pinMode as OUTPUT
    pinMode(_pin, OUTPUT);

    // Calculate the toggle count
    if (duration > 0) {
      toggle_counts[_index] = 2 * frequency * duration / 1000;
    } else {
      toggle_counts[_index] = -1;
    }

    // set up the interrupt frequency
    switch (tone_timers[_index]) {
      case 0:
        // Not currently supported
        break;

      case 1:
        timer1_disable();
        timer1_isr_init();
        timer1_attachInterrupt(t1IntHandler);
        timer1_enable(TIM_DIV1, TIM_EDGE, TIM_LOOP);
        timer1_write((clockCyclesPerMicrosecond() * 500000) / frequency);
        break;
    }
  }
}
Exemplo n.º 3
0
void pwm_start_timer()
{
    timer1_disable();
    ETS_FRC_TIMER1_INTR_ATTACH(NULL, NULL);
    ETS_FRC_TIMER1_NMI_INTR_ATTACH(pwm_timer_isr);
    timer1_enable(TIM_DIV1, TIM_EDGE, TIM_SINGLE);
    timer1_write(1);
}
Exemplo n.º 4
0
void onRcTimer(){
	static uint8_t rc_current_chan = 0;
	static uint16_t rc_loop_time = 0;
	if(rc_current_chan != RC_OUTNUM){
		uint16_t period = rc_outputs[rc_current_chan];
		timer1_write(period * 5);
		if(rc_current_chan != 0) digitalWrite(rc_out_pins[rc_current_chan - 1], LOW);
		digitalWrite(rc_out_pins[rc_current_chan], HIGH);
		rc_loop_time += period;
		rc_current_chan++;
	} else {
		timer1_write((10000 - rc_loop_time) * 5);
		digitalWrite(rc_out_pins[3], LOW);
		rc_loop_time = 0;
		rc_current_chan = 0;
	}
}
Exemplo n.º 5
0
void rcOutputsInit(){
	int i;
	for(i=0; i<RC_OUTNUM; i++){
		pinMode(rc_out_pins[i], OUTPUT);
		digitalWrite(rc_out_pins[i], LOW);
	}
	//updates the screen every second
	timer1_disable();
	timer1_attachInterrupt(onRcTimer);
	timer1_enable(TIM_DIV16, TIM_EDGE, TIM_SINGLE);
	timer1_write(5000000);//1 second
}
Exemplo n.º 6
0
void ICACHE_RAM_ATTR pwm_timer_isr(){
	static uint8_t current_step = 0;
	static uint8_t stepcount = 0;
	static uint16_t steps[17];
	static uint32_t masks[17];
	if(current_step < stepcount){
		GPOC = masks[current_step] & 0xFFFF;
		if(masks[current_step] & 0x10000) GP16O &= ~1;
		current_step++;
		timer1_write(pwm_steps[current_step] * pwm_multiplier);
	} else {

		current_step = 0;
		stepcount = 0;
		if(pwm_mask == 0) return;
		GPOS = pwm_mask & 0xFFFF;
		if(pwm_mask & 0x10000) GP16O |= 1;
		timer1_write(pwm_steps[0] * pwm_multiplier);
		stepcount = pwm_steps_len;
		memcpy(steps, pwm_steps, (stepcount + 1) * 2);
		memcpy(masks, pwm_steps_mask, stepcount * 4);
	}
}
Exemplo n.º 7
0
void pwm_start_timer(){
	timer1_disable();
	timer1_attachInterrupt(pwm_timer_isr);
	timer1_enable(TIM_DIV1, TIM_EDGE, TIM_SINGLE);
	timer1_write(1);
}