Beispiel #1
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;
    }
  }
}
static void initTimer() {
  timer1_disable();
  timer1_isr_init();
  timer1_attachInterrupt(timer1Interrupt);
  lastCycleCount = GetCycleCount();
  timer1_enable(TIM_DIV1, TIM_EDGE, TIM_SINGLE);
  timerRunning = true;
}
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);
}
Beispiel #4
0
/**
 * MOTORSコマンドの送信
 */
int roomba_send_motors (int main_brush, int vacuum, int side_brush)
{
    int size;
    static char buff[64];
    size = roi_set_motors (buff, main_brush, vacuum, side_brush);
    timer1_disable ();
    uart2_send_data (buff, size);
    timer1_enable ();
}
Beispiel #5
0
/**
 * DRIVEコマンドの設定
 */
void roomba_send_drive (short v, short r)
{
    int size;
    static char buff[64];
    size = roi_set_drive (buff, v, r);
    timer1_disable ();
    uart2_send_data (buff, size);
    timer1_enable ();
}
Beispiel #6
0
/**
 * DRIVEコマンドの設定
 */
void roomba_set_drive (short v, short r)
{
    /* タイマ割り込みの停止 */
    timer1_disable ();
    roomba_drive_v = v;
    roomba_drive_r = r;
    /* タイマ割り込みの開始 */
    timer1_enable ();
}
Beispiel #7
0
/**
 * CLEANコマンドの設定
 */
void roomba_send_clean (void)
{
    int size;
    static char buff[64];
    size = roi_set_clean (buff);
    timer1_disable ();
    uart2_send_data (buff, size);
    timer1_enable ();
}
Beispiel #8
0
/**
 * SAFEコマンドの設定
 */
void roomba_send_safe (void)
{
    int size;
    char buff[64];
    size = roi_set_safe (buff);
    timer1_disable ();
    uart2_send_data (buff, size);
    timer1_enable ();
}
Beispiel #9
0
/**
 * CONTROLコマンドの設定
 */
void roomba_send_control (void)
{
    int size;
    char buff[32];
    size = roi_set_control (buff);
    timer1_disable ();
    uart2_send_data (buff, size);
    timer1_enable ();
}
Beispiel #10
0
/**
 * STREAMコマンドの設定
 */
int roomba_send_stream (void)
{
    int size;
    char buff[64];
    size = roi_set_stream (buff, 6);
    timer1_disable ();
    uart2_send_data (buff, size);
    timer1_enable ();
}
void ICACHE_RAM_ATTR pwm_stop_pin(uint8_t pin)
{
    if(pwm_mask) {
        pwm_mask &= ~(1 << pin);
        if(pwm_mask == 0) {
            ETS_FRC_TIMER1_NMI_INTR_ATTACH(NULL);
            timer1_disable();
            timer1_isr_init();
        }
    }
}
Beispiel #12
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
}
Beispiel #13
0
void disableTimer(uint8_t _index) {
  tone_pins[_index] = 255;

  switch (tone_timers[_index]) {
    case 0:
      // Not currently supported
      break;

    case 1:
      timer1_disable();
      break;
  }
}
Beispiel #14
0
extern void __analogWrite(uint8_t pin, int value) {
	bool start_timer = false;
	if(value == 0){
		pwm_mask &= ~(1 << pin);
		prep_pwm_steps();
		digitalWrite(pin, LOW);
		if(pwm_mask == 0) timer1_disable();
		return;
	}
	if((pwm_mask & (1 << pin)) == 0){
		if(pwm_mask == 0) start_timer = true;
		pwm_mask |= (1 << pin);
		pinMode(pin, OUTPUT);
		digitalWrite(pin, LOW);
	}
	pwm_values[pin] = value % (pwm_range + 1);
	prep_pwm_steps();
	if(start_timer){
		pwm_start_timer();
	}
}
Beispiel #15
0
static void deinitTimer() {
  timer1_attachInterrupt(NULL);
  timer1_disable();
  timer1_isr_init();
  timerRunning = false;
}
Beispiel #16
0
void pwm_start_timer(){
	timer1_disable();
	timer1_attachInterrupt(pwm_timer_isr);
	timer1_enable(TIM_DIV1, TIM_EDGE, TIM_SINGLE);
	timer1_write(1);
}
Beispiel #17
0
/**
 * @brief get sensor stream from roomba
 * @param buff buffer to receive stream data
 * @param size size of the buffer
 */
void roomba_get_stream (char* buff, int size)
{
    timer1_disable ();
    memcpy (buff, roomba_stream_buff, size);
    timer1_enable ();
}