/**
 * Put the ADXL362 into a lower power standby state without gating power
 * @Note Accel need to stay
 * @todo Implement this function
 */
void ACCEL_standby() {

		lowPowerSleep(LPM_5ms);
		SPI_transaction(gpRxBuf, (uint8_t*)&ADXL_RESET, sizeof(ADXL_RESET),ACCEL_SPI);
		lowPowerSleep(LPM_1ms);
		SPI_transaction(gpRxBuf, (uint8_t*)&ADXL_CONFIG_STBY, sizeof(ADXL_CONFIG_STBY),ACCEL_SPI);
}
/**
* @brief: Read one byte from EPD register
*/
uint8_t SPI_READ(const uint8_t Register) {
	uint8_t Index[2];
	uint8_t Data[2]	= {0x73,0x00};
	unsigned char RxData[2]	= {0x00,0x00};
	delay_us(T_10us);
	Index[0]=0x70;
	Index[1]=Register;

	SPI_transaction(RxData,Index,2,EPD_SPI);
	delay_us(T_10us);
	SPI_transaction(RxData,Data,2,EPD_SPI);
	return RxData[1];
}
/**
 * Turn on and start up the ADXL362 accelerometer. This leaves the ADXL running.
 */
void initACCEL() {

	/*sleep 5msto allow Accel to startup*/
	lowPowerSleep(LPM_5ms);
	SPI_transaction(gpRxBuf, (uint8_t*)&ADXL_RESET, sizeof(ADXL_RESET),ACCEL_SPI);
	lowPowerSleep(LPM_1ms);
	SPI_transaction(gpRxBuf, (uint8_t*)&ADXL_CONFIG_DETECT, sizeof(ADXL_CONFIG_DETECT),ACCEL_SPI);

	//lowPowerSleep(LPM_1ms);
	//SPI_transaction(gpRxBuf, (uint8_t*)&ADXL_CONFIG_READ, sizeof(ADXL_CONFIG_READ),ACCEL_SPI);
	//lowPowerSleep(LPM_1ms);

}
/**
* @brief: send one byte EPD command, include one byte register_index and one byte data
*/
void epd_spi_send_byte (const uint8_t register_index, const uint8_t register_data) {
	uint8_t  Index[2];
	uint8_t  Data[2];
	const unsigned char RxData[2]	= {0x00,0x00};

	delay_us(T_10us);
	Index[0]= 0x70;
	Index[1]= register_index;
	Data[0]= 0x72;
	Data[1]= register_data;

	SPI_transaction((uint8_t*)RxData,Index,2,EPD_SPI);
	delay_us(T_10us);
	SPI_transaction((uint8_t*)RxData,Data,2,EPD_SPI);
}
/**
 * Grab configure from the ADXL362 accelerometer
 */
BOOL ACCEL_readConfig() {
	//ACCEL_Enable();
	//SPI_transaction(gpRxBuf, (uint8_t*)&ADXL_READ_XYZ_STATUS_8BIT, sizeof(ADXL_READ_XYZ_STATUS_8BIT));
    SPI_transaction(gpRxBuf, (uint8_t*)&ADXL_CONFIG_READ, sizeof(ADXL_CONFIG_READ),ACCEL_SPI);
	//SPI_releasePort();
	return SUCCESS;
}
/**
* @brief: send more than two bytes to EPD register
*/
void epd_spi_send (uint8_t register_index, uint8_t *dataPtr,
		uint8_t length) {
	unsigned char Index[2];
	unsigned char RxData[2]	= {0x00,0x00};
	delay_us(T_10us);
	Index[0]= 0x70;
	Index[1]=register_index;
	SPI_transaction(RxData,Index,2,EPD_SPI);
	delay_us(T_10us);
    //transmit data
	//while(SPI_acquirePort());
	spiSM.target = EPD_LONG_DATA;
	//spiSM.uiCurRx = 0;
	spiSM.uiCurTx = 0;
	spiSM.uiBytesToSend = length+1;
	spiSM.pcRxBuffer = (void *)0;
	spiSM.pcTxBuffer = dataPtr-1;//Tricks:we have to send out the header
	UCB1IE |= UCRXIE;
	EPD_SPI_ON();
	// Start transmission
	UCB1TXBUF = 0x72;
	// Sleep until receive occurs
	__bis_SR_register(LPM4_bits | GIE);
	EPD_SPI_OFF();
	delay_us(T_10us);
	//SPI_releasePort();
}
/**
 * Grab one sample from the ADXL362 accelerometer
 */
BOOL ACCEL_singleSample(uint8_t* dataPack) {
	//ACCEL_Enable();
	//while(SPI_acquirePort());
	SPI_transaction(gpRxBuf, (uint8_t*)&ADXL_READ_XYZ_STATUS_8BIT, sizeof(ADXL_READ_XYZ_STATUS_8BIT),ACCEL_SPI);

	dataPack[3] = gpRxBuf[2]; //X-axis
	dataPack[4] = gpRxBuf[3]; //Y
	dataPack[5] = gpRxBuf[4]; //z
	dataPack[6] = gpRxBuf[5]; //This is the status data
	//SPI_releasePort();
	return SUCCESS;
}
예제 #8
0
파일: accel.c 프로젝트: CMUAbstract/dino
BOOL ACCEL_readID(threeAxis_t* result) {

    while(!SPI_acquirePort());

    BITCLR(POUT_ACCEL_CS, PIN_ACCEL_CS);
    SPI_transaction(gpRxBuf, (uint8_t*)ADXL_READ_DEVID, sizeof(ADXL_READ_DEVID));
    BITSET(POUT_ACCEL_CS, PIN_ACCEL_CS);

    SPI_releasePort();

    result->x = gpRxBuf[2];

    return SUCCESS;
}
예제 #9
0
파일: accel.c 프로젝트: CMUAbstract/dino
/**
 * Grab one sample from the ADXL362 accelerometer
 */
BOOL ACCEL_singleSample(threeAxis_t* result) {

    while(!SPI_acquirePort());

    BITCLR(POUT_ACCEL_CS, PIN_ACCEL_CS);
    SPI_transaction(gpRxBuf, (uint8_t*)ADXL_READ_XYZ_8BIT, sizeof(ADXL_READ_XYZ_8BIT));
    BITSET(POUT_ACCEL_CS, PIN_ACCEL_CS);

    SPI_releasePort();

    result->x = gpRxBuf[2];
    result->y = gpRxBuf[3];
    result->z = gpRxBuf[4];

    return SUCCESS;
}
예제 #10
0
파일: accel.c 프로젝트: CMUAbstract/dino
BOOL ACCEL_initialize_withoutWait() {

    // TODO Figure out optimal ADXL configuration for single measurement
    while(!SPI_acquirePort());
    //BITSET(POUT_ACCEL_EN, PIN_ACCEL_EN);
    BITSET(POUT_ACCEL_CS, PIN_ACCEL_CS);
    BITCLR(POUT_ACCEL_CS, PIN_ACCEL_CS);

    SPI_transaction(gpRxBuf, (uint8_t*)ADXL_CONFIG_MEAS, sizeof(ADXL_CONFIG_MEAS));
    BITSET(POUT_ACCEL_CS, PIN_ACCEL_CS);

    SPI_releasePort();

    //Timer_LooseDelay(LP_LSDLY_200MS);// To let ADXL start measuring? How much time is actually required here, if any?

    // TODO Use a pin interrupt to let us know when first measurement is ready
    return SUCCESS;
}
예제 #11
0
파일: accel.c 프로젝트: CMUAbstract/dino
BOOL ACCEL_range() {

    // TODO Figure out optimal ADXL configuration for single measurement
    while(!SPI_acquirePort());
    //BITSET(POUT_ACCEL_EN, PIN_ACCEL_EN);
    //BITSET(POUT_ACCEL_CS, PIN_ACCEL_CS);

    //TODO find the proper length of delay

    BITCLR(POUT_ACCEL_CS, PIN_ACCEL_CS);
    SPI_transaction(gpRxBuf, (uint8_t*)ADXL_CONFIG_FILTER, sizeof(ADXL_CONFIG_FILTER));
    BITSET(POUT_ACCEL_CS, PIN_ACCEL_CS);

    SPI_releasePort();

    //__delay_cycles(5000);

    //Timer_LooseDelay(LP_LSDLY_200MS);// To let ADXL start measuring? How much time is actually required here, if any?

    // TODO Use a pin interrupt to let us know when first measurement is ready
    return SUCCESS;
}
/**
 * Grab one ADXL_READ_STATUS from the ADXL362 accelerometer
 */
BOOL ACCEL_Status(uint8_t* result) {
    	SPI_transaction(gpRxBuf, (uint8_t*)&ADXL_READ_STATUS, sizeof(ADXL_READ_STATUS),ACCEL_SPI);
		*(result)   = gpRxBuf[2];
	return SUCCESS;
}
예제 #13
0
static PyObject *SPIDev_transaction(SPIDev *self, PyObject *args, PyObject *kwds) {
  uint8_t cs;
  uint32_t n_tx_bytes, n_rx_bytes, n_tx_words, n_rx_words, i, word;
  PyObject *txdata, *rxdata, *word_obj;
  void *txbuf, *rxbuf;

  cs = 0;
  if(!PyArg_ParseTuple(args, "bO!b", &cs, &PyList_Type, &txdata, &n_rx_words)) {
    return NULL;
  }

  if (SPIDev_activateCS(self, cs) < 0) return NULL;

  n_tx_words = PyList_Size(txdata);
  n_tx_bytes = (uint32_t) (((float) (self->bits_per_word * n_tx_words)) / 8.0 + 0.5);
  n_rx_bytes = (uint32_t) (((float) (self->bits_per_word * n_rx_words)) / 8.0 + 0.5);
  txbuf = malloc(n_tx_bytes);
  rxbuf = malloc(n_rx_bytes);

  for (i=0; i<n_tx_words; i++) {
    word_obj = PyList_GetItem(txdata, i);
    if (!PyInt_Check(word_obj)) {
      PyErr_SetString(PyExc_ValueError,
        "data list to transmit can only contain integers");
      free(rxbuf);
      free(txbuf);
      return NULL;
    }
    word = PyInt_AsLong(word_obj);
    if (word < 0) {
      if (PyErr_Occurred() != NULL) {
          free(rxbuf);
          free(txbuf);
          return NULL;
      }
      word = 0;
    }
    switch(self->bytes_per_word) {
    case 1:
      ((uint8_t*)txbuf)[i] = (uint8_t) word;
      break;
    case 2:
      ((uint16_t*)txbuf)[i] = (uint16_t) word;
      break;
    case 4:
      ((uint32_t*)txbuf)[i] = (uint32_t) word;
      break;
    default:
      break;
    }
  }
  n_rx_words = SPI_transaction(self->spidev_fd[cs], txbuf, n_tx_words, rxbuf, 
                               n_rx_words);
  rxdata = PyList_New(0);
  for (i=0; i<n_rx_words; i++) {
    switch(self->bytes_per_word) {
    case 1:
      word = ((uint8_t*)rxbuf)[i];
      break;
    case 2:
      word = ((uint16_t*)rxbuf)[i];
      break;
    case 4:
      word = ((uint32_t*)rxbuf)[i];
      break;
    default:
      word = 0;
      break;
    }
    word_obj = PyInt_FromLong(word);
    PyList_Append(rxdata, word_obj);
    Py_DECREF(word_obj);
  }
  free(txbuf);
  free(rxbuf);
  return rxdata;
}