Skip to content

Commit c476bec

Browse files
committed
update
1 parent 1d349b6 commit c476bec

File tree

237 files changed

+32014
-34551
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

237 files changed

+32014
-34551
lines changed

Seeed_Arduino_LIS3DHTR/LIS3DHTR.cpp

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -35,60 +35,60 @@ LIS3DHTR<T>::LIS3DHTR()
3535

3636
}
3737

38-
//template <class T>
39-
//void LIS3DHTR<T>::begin(SPIClass &comm, uint8_t sspin)
40-
//{
41-
// chipSelectPin = sspin;
42-
// _spi_com = &comm;
43-
// _wire_com = NULL;
44-
// pinMode(chipSelectPin, OUTPUT);
45-
// digitalWrite(chipSelectPin, HIGH);
38+
template <class T>
39+
void LIS3DHTR<T>::begin(SPIClass &comm, uint8_t sspin)
40+
{
41+
chipSelectPin = sspin;
42+
_spi_com = &comm;
43+
_wire_com = NULL;
44+
pinMode(chipSelectPin, OUTPUT);
45+
digitalWrite(chipSelectPin, HIGH);
4646

47-
// // Maximum SPI frequency is 10MHz, Data is read and written MSb first,
48-
// // Data is captured on rising edge of clock (CPHA = 0)
49-
// // Base value of the clock is HIGH (CPOL = 1)
50-
// // MODE3 for 328p operation
51-
// SPISettings _settings(10000000, MSBFIRST, SPI_MODE3);
47+
// Maximum SPI frequency is 10MHz, Data is read and written MSb first,
48+
// Data is captured on rising edge of clock (CPHA = 0)
49+
// Base value of the clock is HIGH (CPOL = 1)
50+
// MODE3 for 328p operation
51+
SPISettings _settings(10000000, MSBFIRST, SPI_MODE3);
5252

53-
// // start the SPI library:
54-
// _spi_com->begin();
53+
// start the SPI library:
54+
_spi_com->begin();
5555

56-
// delay(200);
56+
delay(200);
5757

58-
// uint8_t config5 = LIS3DHTR_REG_TEMP_ADC_PD_ENABLED |
59-
// LIS3DHTR_REG_TEMP_TEMP_EN_DISABLED;
58+
uint8_t config5 = LIS3DHTR_REG_TEMP_ADC_PD_ENABLED |
59+
LIS3DHTR_REG_TEMP_TEMP_EN_DISABLED;
6060

61-
// writeRegister(LIS3DHTR_REG_TEMP_CFG, config5);
62-
// delay(LIS3DHTR_CONVERSIONDELAY);
61+
writeRegister(LIS3DHTR_REG_TEMP_CFG, config5);
62+
delay(LIS3DHTR_CONVERSIONDELAY);
6363

64-
// uint8_t config1 = LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_NORMAL | // Normal Mode
65-
// LIS3DHTR_REG_ACCEL_CTRL_REG1_AZEN_ENABLE | // Acceleration Z-Axis Enabled
66-
// LIS3DHTR_REG_ACCEL_CTRL_REG1_AYEN_ENABLE | // Acceleration Y-Axis Enabled
67-
// LIS3DHTR_REG_ACCEL_CTRL_REG1_AXEN_ENABLE;
64+
uint8_t config1 = LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_NORMAL | // Normal Mode
65+
LIS3DHTR_REG_ACCEL_CTRL_REG1_AZEN_ENABLE | // Acceleration Z-Axis Enabled
66+
LIS3DHTR_REG_ACCEL_CTRL_REG1_AYEN_ENABLE | // Acceleration Y-Axis Enabled
67+
LIS3DHTR_REG_ACCEL_CTRL_REG1_AXEN_ENABLE;
6868

69-
// writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG1, config1);
70-
// delay(LIS3DHTR_CONVERSIONDELAY);
69+
writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG1, config1);
70+
delay(LIS3DHTR_CONVERSIONDELAY);
7171

72-
// uint8_t config4 = LIS3DHTR_REG_ACCEL_CTRL_REG4_BDU_NOTUPDATED | // Continuous Update
73-
// LIS3DHTR_REG_ACCEL_CTRL_REG4_BLE_LSB | // Data LSB @ lower address
74-
// LIS3DHTR_REG_ACCEL_CTRL_REG4_HS_DISABLE | // High Resolution Disable
75-
// LIS3DHTR_REG_ACCEL_CTRL_REG4_ST_NORMAL | // Normal Mode
76-
// LIS3DHTR_REG_ACCEL_CTRL_REG4_SIM_4WIRE; // 4-Wire Interface
72+
uint8_t config4 = LIS3DHTR_REG_ACCEL_CTRL_REG4_BDU_NOTUPDATED | // Continuous Update
73+
LIS3DHTR_REG_ACCEL_CTRL_REG4_BLE_LSB | // Data LSB @ lower address
74+
LIS3DHTR_REG_ACCEL_CTRL_REG4_HS_DISABLE | // High Resolution Disable
75+
LIS3DHTR_REG_ACCEL_CTRL_REG4_ST_NORMAL | // Normal Mode
76+
LIS3DHTR_REG_ACCEL_CTRL_REG4_SIM_4WIRE; // 4-Wire Interface
7777

78-
// writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG4, config4);
78+
writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG4, config4);
7979

80-
// delay(LIS3DHTR_CONVERSIONDELAY);
80+
delay(LIS3DHTR_CONVERSIONDELAY);
8181

82-
// setFullScaleRange(LIS3DHTR_RANGE_16G);
83-
// setOutputDataRate(LIS3DHTR_DATARATE_400HZ);
84-
//}
82+
setFullScaleRange(LIS3DHTR_RANGE_16G);
83+
setOutputDataRate(LIS3DHTR_DATARATE_400HZ);
84+
}
8585

8686
template <class T>
8787
void LIS3DHTR<T>::begin(TwoWire &wire, uint8_t address)
8888
{
8989
_wire_com = &wire;
9090
_wire_com->begin();
91-
// _spi_com = NULL;
91+
_spi_com = NULL;
9292
devAddr = address;
9393

9494
uint8_t config5 = LIS3DHTR_REG_TEMP_ADC_PD_ENABLED |
@@ -360,22 +360,22 @@ uint16_t LIS3DHTR<T>::readbitADC3(void)
360360
template <class T>
361361
void LIS3DHTR<T>::writeRegister(uint8_t reg, uint8_t val)
362362
{
363-
// if (_spi_com != NULL)
364-
// {
365-
// _spi_com->beginTransaction(_settings);
366-
// digitalWrite(chipSelectPin, LOW);
367-
// _spi_com->transfer(reg);
368-
// _spi_com->transfer(val);
369-
// digitalWrite(chipSelectPin, HIGH);
370-
// _spi_com->endTransaction();
371-
// }
372-
// else
373-
// {
363+
if (_spi_com != NULL)
364+
{
365+
_spi_com->beginTransaction(_settings);
366+
digitalWrite(chipSelectPin, LOW);
367+
_spi_com->transfer(reg);
368+
_spi_com->transfer(val);
369+
digitalWrite(chipSelectPin, HIGH);
370+
_spi_com->endTransaction();
371+
}
372+
else
373+
{
374374
_wire_com->beginTransmission(devAddr);
375375
_wire_com->write(reg);
376376
_wire_com->write(val);
377377
_wire_com->endTransmission();
378-
// }
378+
}
379379
}
380380

381381
template <class T>
@@ -386,23 +386,23 @@ void LIS3DHTR<T>::readRegisterRegion(uint8_t *outputPointer, uint8_t reg, uint8_
386386
uint8_t i = 0;
387387
uint8_t c = 0;
388388

389-
// if (_spi_com != NULL)
390-
// {
391-
// _spi_com->beginTransaction(_settings);
392-
// digitalWrite(chipSelectPin, LOW);
393-
// _spi_com->transfer(reg | 0x80 | 0x40); //Ored with "read request" bit and "auto increment" bit
394-
// while (i < length) // slave may send less than requested
395-
// {
396-
// c = _spi_com->transfer(0x00); // receive a byte as character
397-
// *outputPointer = c;
398-
// outputPointer++;
399-
// i++;
400-
// }
401-
// digitalWrite(chipSelectPin, HIGH);
402-
// _spi_com->endTransaction();
403-
// }
404-
// else
405-
// {
389+
if (_spi_com != NULL)
390+
{
391+
_spi_com->beginTransaction(_settings);
392+
digitalWrite(chipSelectPin, LOW);
393+
_spi_com->transfer(reg | 0x80 | 0x40); //Ored with "read request" bit and "auto increment" bit
394+
while (i < length) // slave may send less than requested
395+
{
396+
c = _spi_com->transfer(0x00); // receive a byte as character
397+
*outputPointer = c;
398+
outputPointer++;
399+
i++;
400+
}
401+
digitalWrite(chipSelectPin, HIGH);
402+
_spi_com->endTransaction();
403+
}
404+
else
405+
{
406406

407407
_wire_com->beginTransmission(devAddr);
408408
reg |= 0x80; //turn auto-increment bit on, bit 7 for I2C
@@ -417,7 +417,7 @@ void LIS3DHTR<T>::readRegisterRegion(uint8_t *outputPointer, uint8_t reg, uint8_
417417
outputPointer++;
418418
i++;
419419
}
420-
// }
420+
}
421421
}
422422

423423
template <class T>
@@ -473,5 +473,5 @@ void LIS3DHTR<T>::click(uint8_t c, uint8_t click_thresh, uint8_t limit, uint8_t
473473
template <class T>
474474
LIS3DHTR<T>::operator bool() { return isConnection(); }
475475

476-
//template class LIS3DHTR<SPIClass>;
476+
template class LIS3DHTR<SPIClass>;
477477
template class LIS3DHTR<TwoWire>;

Seeed_Arduino_LIS3DHTR/LIS3DHTR.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#endif
3232

3333
#include <Wire.h>
34+
#include <SPI.h>
35+
3436

3537
#ifndef SEEED_LIS3DHTR_H
3638
#define SEEED_LIS3DHTR_H
@@ -195,7 +197,7 @@ class LIS3DHTR
195197

196198
bool isConnection(void);
197199

198-
//void begin(SPIClass &comm = SPI, uint8_t sspin = SS); //init
200+
void begin(SPIClass &comm = SPI, uint8_t sspin = 10/*SS*/); //init
199201
void begin(TwoWire &comm = Wire, uint8_t address = LIS3DHTR_DEFAULT_ADDRESS); //init
200202
void begin(uint8_t address) { begin(Wire, address); };
201203

@@ -235,8 +237,8 @@ class LIS3DHTR
235237
int16_t accRange;
236238
uint8_t commInterface;
237239
uint8_t chipSelectPin;
238-
//SPIClass *_spi_com;
239-
//SPISettings _settings;
240+
SPIClass *_spi_com;
241+
SPISettings _settings;
240242
TwoWire *_wire_com;
241243
};
242244

U8g2_Arduino-master/LICENSE

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)