static uint8_t ds_read_bit() { uint8_t i, b = 1; /* Begin a read/write time slot * pull line low for between 1us and 15us */ PIN_LOW(); PIN_OUT(); _delay_us(BEGIN_TIMESLOT); PIN_IN(); _delay_us(DELAY_TIMESLOT); /* If the sensor pulls the line low within * the time slot the bit is 0 */ for(i = 0; i < TIMESLOT - BEGIN_TIMESLOT; i++) { if(!READ_PIN()) b = 0; _delay_us(1); } _delay_us(RECOVERY); return(b); }
static void lcdPrepareWrite(void) { CMD_WRITE(); PIN_OUT(LCD_D0); PIN_OUT(LCD_D1); PIN_OUT(LCD_D2); PIN_OUT(LCD_D3); PIN_OUT(LCD_D4); PIN_OUT(LCD_D5); PIN_OUT(LCD_D6); PIN_OUT(LCD_D7); }
static void ds_write_bit(uint8_t b) { /* Begin a read/write time slot * pull line low for between 1us and 15us */ PIN_LOW(); PIN_OUT(); _delay_us(BEGIN_TIMESLOT); /* "1" is written by releasing the line immediatly */ if(b) PIN_IN(); /* Wait for the write slot to end and then release the line */ _delay_us(TIMESLOT - BEGIN_TIMESLOT); PIN_IN(); _delay_us(RECOVERY); }
static int ds_reset() { /* Reset pulse - pull line low for at least 480us */ PIN_LOW(); PIN_OUT(); _delay_us(RESET_PULSE); PIN_IN(); /* The sensor should respond by pulling the line low * after 15us to 60us for 60us to 240us. Wait for * 80us for the line to go low */ _delay_us(RESET_WAIT_LOW); if(READ_PIN()) return(DS_TIMEOUT); _delay_us(RESET_PULSE - RESET_WAIT_LOW); if(!READ_PIN()) return(DS_TIMEOUT); return(DS_OK); }
/** * @brief Timeslot related events callback * Called whenever the softdevice tries to change the original course of actions * related to the timeslots */ void ts_sd_event_handler(void) { uint32_t evt; SET_PIN(6); while (sd_evt_get(&evt) == NRF_SUCCESS) { PIN_OUT(evt, 32); switch (evt) { case NRF_EVT_RADIO_SESSION_IDLE: timeslot_order_earliest(TIMESLOT_SLOT_LENGTH, true); break; case NRF_EVT_RADIO_SESSION_CLOSED: APP_ERROR_CHECK(NRF_ERROR_INVALID_DATA); break; case NRF_EVT_RADIO_BLOCKED: /* something in the softdevice is blocking our requests, go into emergency mode, where slots are short, in order to avoid complete lockout */ timeslot_order_earliest(TIMESLOT_SLOT_EMERGENCY_LENGTH, true); break; case NRF_EVT_RADIO_SIGNAL_CALLBACK_INVALID_RETURN: APP_ERROR_CHECK(NRF_ERROR_INVALID_DATA); break; case NRF_EVT_RADIO_CANCELED: timeslot_order_earliest(TIMESLOT_SLOT_LENGTH, true); break; default: APP_ERROR_CHECK(NRF_ERROR_INVALID_STATE); } } CLEAR_PIN(6); }