Repo restyled using astyle (#683)
The rules are in .tools/astyle/config/style.cfg and can also be reviewed at https://www.mysensors.org/view/260#coding-guidelines-core-library
This commit is contained in:
+24
-15
@@ -31,11 +31,13 @@ SPIClass SPI = SPIClass();
|
||||
|
||||
uint8_t SPIClass::initialized = 0;
|
||||
|
||||
uint8_t SPIClass::is_initialized() {
|
||||
uint8_t SPIClass::is_initialized()
|
||||
{
|
||||
return initialized;
|
||||
}
|
||||
|
||||
void SPIClass::begin() {
|
||||
void SPIClass::begin()
|
||||
{
|
||||
if (!initialized) {
|
||||
if (!bcm2835_spi_begin()) {
|
||||
logError("You need root privilege to use SPI.\n");
|
||||
@@ -46,7 +48,8 @@ void SPIClass::begin() {
|
||||
initialized++; // reference count
|
||||
}
|
||||
|
||||
void SPIClass::end() {
|
||||
void SPIClass::end()
|
||||
{
|
||||
if (initialized) {
|
||||
initialized--;
|
||||
}
|
||||
@@ -57,47 +60,53 @@ void SPIClass::end() {
|
||||
}
|
||||
}
|
||||
|
||||
void SPIClass::setBitOrder(uint8_t bit_order) {
|
||||
void SPIClass::setBitOrder(uint8_t bit_order)
|
||||
{
|
||||
bcm2835_spi_setBitOrder(bit_order);
|
||||
}
|
||||
|
||||
void SPIClass::setDataMode(uint8_t data_mode) {
|
||||
void SPIClass::setDataMode(uint8_t data_mode)
|
||||
{
|
||||
bcm2835_spi_setDataMode(data_mode);
|
||||
}
|
||||
|
||||
void SPIClass::setClockDivider(uint16_t divider) {
|
||||
void SPIClass::setClockDivider(uint16_t divider)
|
||||
{
|
||||
bcm2835_spi_setClockDivider(divider);
|
||||
}
|
||||
|
||||
void SPIClass::chipSelect(int csn_pin) {
|
||||
void SPIClass::chipSelect(int csn_pin)
|
||||
{
|
||||
if (csn_pin == RPI_GPIO_P1_26) {
|
||||
csn_pin = BCM2835_SPI_CS1;
|
||||
}
|
||||
else if (csn_pin == RPI_GPIO_P1_24) {
|
||||
} else if (csn_pin == RPI_GPIO_P1_24) {
|
||||
csn_pin = BCM2835_SPI_CS0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
csn_pin = BCM2835_SPI_CS0;
|
||||
}
|
||||
bcm2835_spi_chipSelect(csn_pin);
|
||||
delayMicroseconds(5);
|
||||
}
|
||||
|
||||
void SPIClass::beginTransaction(SPISettings settings) {
|
||||
void SPIClass::beginTransaction(SPISettings settings)
|
||||
{
|
||||
pthread_mutex_lock(&spiMutex);
|
||||
setBitOrder(settings.border);
|
||||
setDataMode(settings.dmode);
|
||||
setClockDivider(settings.cdiv);
|
||||
}
|
||||
|
||||
void SPIClass::endTransaction() {
|
||||
void SPIClass::endTransaction()
|
||||
{
|
||||
pthread_mutex_unlock(&spiMutex);
|
||||
}
|
||||
|
||||
void SPIClass::usingInterrupt(uint8_t interruptNumber) {
|
||||
void SPIClass::usingInterrupt(uint8_t interruptNumber)
|
||||
{
|
||||
(void)interruptNumber;
|
||||
}
|
||||
|
||||
void SPIClass::notUsingInterrupt(uint8_t interruptNumber) {
|
||||
void SPIClass::notUsingInterrupt(uint8_t interruptNumber)
|
||||
{
|
||||
(void)interruptNumber;
|
||||
}
|
||||
|
||||
+38
-30
@@ -45,7 +45,8 @@
|
||||
/**
|
||||
* SPISettings class
|
||||
*/
|
||||
class SPISettings {
|
||||
class SPISettings
|
||||
{
|
||||
|
||||
public:
|
||||
/**
|
||||
@@ -53,7 +54,8 @@ public:
|
||||
*
|
||||
* Default clock speed is 8Mhz.
|
||||
*/
|
||||
SPISettings() {
|
||||
SPISettings()
|
||||
{
|
||||
init(BCM2835_SPI_CLOCK_DIVIDER_32, BCM2835_SPI_BIT_ORDER_MSBFIRST, BCM2835_SPI_MODE0);
|
||||
}
|
||||
/**
|
||||
@@ -63,31 +65,32 @@ public:
|
||||
* @param bitOrder SPI bit order.
|
||||
* @param dataMode SPI data mode.
|
||||
*/
|
||||
SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) {
|
||||
SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode)
|
||||
{
|
||||
uint16_t divider;
|
||||
|
||||
switch (clock) {
|
||||
case 500000:
|
||||
divider = BCM2835_SPI_CLOCK_DIVIDER_512;
|
||||
break;
|
||||
case 1000000:
|
||||
divider = BCM2835_SPI_CLOCK_DIVIDER_256;
|
||||
break;
|
||||
case 2000000:
|
||||
divider = BCM2835_SPI_CLOCK_DIVIDER_128;
|
||||
break;
|
||||
case 4000000:
|
||||
divider = BCM2835_SPI_CLOCK_DIVIDER_64;
|
||||
break;
|
||||
case 8000000:
|
||||
divider = BCM2835_SPI_CLOCK_DIVIDER_32;
|
||||
break;
|
||||
case 16000000:
|
||||
divider = BCM2835_SPI_CLOCK_DIVIDER_16;
|
||||
break;
|
||||
default:
|
||||
// 8Mhz
|
||||
divider = BCM2835_SPI_CLOCK_DIVIDER_32;
|
||||
case 500000:
|
||||
divider = BCM2835_SPI_CLOCK_DIVIDER_512;
|
||||
break;
|
||||
case 1000000:
|
||||
divider = BCM2835_SPI_CLOCK_DIVIDER_256;
|
||||
break;
|
||||
case 2000000:
|
||||
divider = BCM2835_SPI_CLOCK_DIVIDER_128;
|
||||
break;
|
||||
case 4000000:
|
||||
divider = BCM2835_SPI_CLOCK_DIVIDER_64;
|
||||
break;
|
||||
case 8000000:
|
||||
divider = BCM2835_SPI_CLOCK_DIVIDER_32;
|
||||
break;
|
||||
case 16000000:
|
||||
divider = BCM2835_SPI_CLOCK_DIVIDER_16;
|
||||
break;
|
||||
default:
|
||||
// 8Mhz
|
||||
divider = BCM2835_SPI_CLOCK_DIVIDER_32;
|
||||
}
|
||||
|
||||
init(divider, bitOrder, dataMode);
|
||||
@@ -105,7 +108,8 @@ private:
|
||||
* @param bitOrder SPI bit order.
|
||||
* @param dataMode SPI data mode.
|
||||
*/
|
||||
void init(uint16_t divider, uint8_t bitOrder, uint8_t dataMode) {
|
||||
void init(uint16_t divider, uint8_t bitOrder, uint8_t dataMode)
|
||||
{
|
||||
cdiv = divider;
|
||||
border = bitOrder;
|
||||
dmode = dataMode;
|
||||
@@ -117,7 +121,8 @@ private:
|
||||
/**
|
||||
* SPIClass class
|
||||
*/
|
||||
class SPIClass {
|
||||
class SPIClass
|
||||
{
|
||||
|
||||
private:
|
||||
static uint8_t initialized; //!< @brief SPI initialized flag.
|
||||
@@ -150,7 +155,7 @@ public:
|
||||
* @param buf Buffer to read from and write to.
|
||||
* @param len Buffer length.
|
||||
*/
|
||||
inline static void transfern(char* buf, uint32_t len);
|
||||
inline static void transfern(char* buf, uint32_t len);
|
||||
/**
|
||||
* @brief Start SPI operations.
|
||||
*/
|
||||
@@ -207,15 +212,18 @@ public:
|
||||
static void notUsingInterrupt(uint8_t interruptNumber);
|
||||
};
|
||||
|
||||
uint8_t SPIClass::transfer(uint8_t data) {
|
||||
uint8_t SPIClass::transfer(uint8_t data)
|
||||
{
|
||||
return bcm2835_spi_transfer(data);
|
||||
}
|
||||
|
||||
void SPIClass::transfernb(char* tbuf, char* rbuf, uint32_t len) {
|
||||
void SPIClass::transfernb(char* tbuf, char* rbuf, uint32_t len)
|
||||
{
|
||||
bcm2835_spi_transfernb( tbuf, rbuf, len);
|
||||
}
|
||||
|
||||
void SPIClass::transfern(char* buf, uint32_t len) {
|
||||
void SPIClass::transfern(char* buf, uint32_t len)
|
||||
{
|
||||
transfernb(buf, buf, len);
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ size_t TwoWire::write(uint8_t data)
|
||||
// put byte in tx buffer
|
||||
txBuffer[txBufferIndex] = data;
|
||||
++txBufferIndex;
|
||||
// update amount in buffer
|
||||
// update amount in buffer
|
||||
txBufferLength = txBufferIndex;
|
||||
|
||||
return 1;
|
||||
|
||||
+18
-5
@@ -31,7 +31,8 @@
|
||||
|
||||
#define BUFFER_LENGTH 32
|
||||
|
||||
class TwoWire : public Stream {
|
||||
class TwoWire : public Stream
|
||||
{
|
||||
|
||||
private:
|
||||
static uint8_t rxBuffer[];
|
||||
@@ -67,10 +68,22 @@ public:
|
||||
int peek();
|
||||
void flush();
|
||||
|
||||
inline size_t write(unsigned long n) { return write((uint8_t)n); }
|
||||
inline size_t write(long n) { return write((uint8_t)n); }
|
||||
inline size_t write(unsigned int n) { return write((uint8_t)n); }
|
||||
inline size_t write(int n) { return write((uint8_t)n); }
|
||||
inline size_t write(unsigned long n)
|
||||
{
|
||||
return write((uint8_t)n);
|
||||
}
|
||||
inline size_t write(long n)
|
||||
{
|
||||
return write((uint8_t)n);
|
||||
}
|
||||
inline size_t write(unsigned int n)
|
||||
{
|
||||
return write((uint8_t)n);
|
||||
}
|
||||
inline size_t write(int n)
|
||||
{
|
||||
return write((uint8_t)n);
|
||||
}
|
||||
using Print::write;
|
||||
};
|
||||
|
||||
|
||||
+892
-917
File diff suppressed because it is too large
Load Diff
+898
-909
File diff suppressed because it is too large
Load Diff
+220
-155
@@ -27,167 +27,232 @@ SOFTWARE.
|
||||
|
||||
int get_rpi_info(rpi_info *info)
|
||||
{
|
||||
FILE *fp;
|
||||
char buffer[1024];
|
||||
char hardware[1024];
|
||||
char revision[1024];
|
||||
char *rev;
|
||||
int found = 0;
|
||||
int len;
|
||||
FILE *fp;
|
||||
char buffer[1024];
|
||||
char hardware[1024];
|
||||
char revision[1024];
|
||||
char *rev;
|
||||
int found = 0;
|
||||
int len;
|
||||
|
||||
if ((fp = fopen("/proc/cpuinfo", "r")) == NULL)
|
||||
return -1;
|
||||
while(!feof(fp)) {
|
||||
fgets(buffer, sizeof(buffer), fp);
|
||||
sscanf(buffer, "Hardware : %s", hardware);
|
||||
if (strcmp(hardware, "BCM2708") == 0 ||
|
||||
strcmp(hardware, "BCM2709") == 0 ||
|
||||
strcmp(hardware, "BCM2835") == 0 ||
|
||||
strcmp(hardware, "BCM2836") == 0 ||
|
||||
strcmp(hardware, "BCM2837") == 0 ) {
|
||||
found = 1;
|
||||
}
|
||||
sscanf(buffer, "Revision : %s", revision);
|
||||
}
|
||||
fclose(fp);
|
||||
if ((fp = fopen("/proc/cpuinfo", "r")) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
while(!feof(fp)) {
|
||||
fgets(buffer, sizeof(buffer), fp);
|
||||
sscanf(buffer, "Hardware : %s", hardware);
|
||||
if (strcmp(hardware, "BCM2708") == 0 ||
|
||||
strcmp(hardware, "BCM2709") == 0 ||
|
||||
strcmp(hardware, "BCM2835") == 0 ||
|
||||
strcmp(hardware, "BCM2836") == 0 ||
|
||||
strcmp(hardware, "BCM2837") == 0 ) {
|
||||
found = 1;
|
||||
}
|
||||
sscanf(buffer, "Revision : %s", revision);
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
if (!found)
|
||||
return -1;
|
||||
if (!found) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((len = strlen(revision)) == 0)
|
||||
return -1;
|
||||
if ((len = strlen(revision)) == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (len >= 6 && strtol((char[]){revision[len-6],0}, NULL, 16) & 8) {
|
||||
// new scheme
|
||||
//info->rev = revision[len-1]-'0';
|
||||
strcpy(info->revision, revision);
|
||||
switch (revision[len-2]) {
|
||||
case '0': info->type = "Model A"; info->p1_revision = 2; break;
|
||||
case '1': info->type = "Model B"; info->p1_revision = 2; break;
|
||||
case '2': info->type = "Model A+"; info->p1_revision = 3; break;
|
||||
case '3': info->type = "Model B+"; info->p1_revision = 3; break;
|
||||
case '4': info->type = "Pi 2 Model B"; info->p1_revision = 3; break;
|
||||
case '5': info->type = "Alpha"; info->p1_revision = 3; break;
|
||||
case '6': info->type = "Compute"; info->p1_revision = 0; break;
|
||||
case '8': info->type = "Pi 3 Model B"; info->p1_revision = 3; break;
|
||||
case '9': info->type = "Zero"; info->p1_revision = 3; break;
|
||||
default : info->type = "Unknown"; info->p1_revision = 3; break;
|
||||
}
|
||||
switch (revision[len-4]) {
|
||||
case '0': info->processor = "BCM2835"; break;
|
||||
case '1': info->processor = "BCM2836"; break;
|
||||
case '2': info->processor = "BCM2837"; break;
|
||||
default : info->processor = "Unknown"; break;
|
||||
}
|
||||
switch (revision[len-5]) {
|
||||
case '0': info->manufacturer = "Sony"; break;
|
||||
case '1': info->manufacturer = "Egoman"; break;
|
||||
case '2': info->manufacturer = "Embest"; break;
|
||||
case '4': info->manufacturer = "Embest"; break;
|
||||
default : info->manufacturer = "Unknown"; break;
|
||||
}
|
||||
switch (strtol((char[]){revision[len-6],0}, NULL, 16) & 7) {
|
||||
case 0: info->ram = "256M"; break;
|
||||
case 1: info->ram = "512M"; break;
|
||||
case 2: info->ram = "1024M"; break;
|
||||
default: info->ram = "Unknown"; break;
|
||||
}
|
||||
} else {
|
||||
// old scheme
|
||||
info->ram = "Unknown";
|
||||
info->manufacturer = "Unknown";
|
||||
info->processor = "Unknown";
|
||||
info->type = "Unknown";
|
||||
strcpy(info->revision, revision);
|
||||
if (len >= 6 && strtol((char[]) {
|
||||
revision[len-6],0
|
||||
}, NULL, 16) & 8) {
|
||||
// new scheme
|
||||
//info->rev = revision[len-1]-'0';
|
||||
strcpy(info->revision, revision);
|
||||
switch (revision[len-2]) {
|
||||
case '0':
|
||||
info->type = "Model A";
|
||||
info->p1_revision = 2;
|
||||
break;
|
||||
case '1':
|
||||
info->type = "Model B";
|
||||
info->p1_revision = 2;
|
||||
break;
|
||||
case '2':
|
||||
info->type = "Model A+";
|
||||
info->p1_revision = 3;
|
||||
break;
|
||||
case '3':
|
||||
info->type = "Model B+";
|
||||
info->p1_revision = 3;
|
||||
break;
|
||||
case '4':
|
||||
info->type = "Pi 2 Model B";
|
||||
info->p1_revision = 3;
|
||||
break;
|
||||
case '5':
|
||||
info->type = "Alpha";
|
||||
info->p1_revision = 3;
|
||||
break;
|
||||
case '6':
|
||||
info->type = "Compute";
|
||||
info->p1_revision = 0;
|
||||
break;
|
||||
case '8':
|
||||
info->type = "Pi 3 Model B";
|
||||
info->p1_revision = 3;
|
||||
break;
|
||||
case '9':
|
||||
info->type = "Zero";
|
||||
info->p1_revision = 3;
|
||||
break;
|
||||
default :
|
||||
info->type = "Unknown";
|
||||
info->p1_revision = 3;
|
||||
break;
|
||||
}
|
||||
switch (revision[len-4]) {
|
||||
case '0':
|
||||
info->processor = "BCM2835";
|
||||
break;
|
||||
case '1':
|
||||
info->processor = "BCM2836";
|
||||
break;
|
||||
case '2':
|
||||
info->processor = "BCM2837";
|
||||
break;
|
||||
default :
|
||||
info->processor = "Unknown";
|
||||
break;
|
||||
}
|
||||
switch (revision[len-5]) {
|
||||
case '0':
|
||||
info->manufacturer = "Sony";
|
||||
break;
|
||||
case '1':
|
||||
info->manufacturer = "Egoman";
|
||||
break;
|
||||
case '2':
|
||||
info->manufacturer = "Embest";
|
||||
break;
|
||||
case '4':
|
||||
info->manufacturer = "Embest";
|
||||
break;
|
||||
default :
|
||||
info->manufacturer = "Unknown";
|
||||
break;
|
||||
}
|
||||
switch (strtol((char[]) {
|
||||
revision[len-6],0
|
||||
}, NULL, 16) & 7) {
|
||||
case 0:
|
||||
info->ram = "256M";
|
||||
break;
|
||||
case 1:
|
||||
info->ram = "512M";
|
||||
break;
|
||||
case 2:
|
||||
info->ram = "1024M";
|
||||
break;
|
||||
default:
|
||||
info->ram = "Unknown";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// old scheme
|
||||
info->ram = "Unknown";
|
||||
info->manufacturer = "Unknown";
|
||||
info->processor = "Unknown";
|
||||
info->type = "Unknown";
|
||||
strcpy(info->revision, revision);
|
||||
|
||||
// get last four characters (ignore preceeding 1000 for overvolt)
|
||||
if (len > 4)
|
||||
rev = (char *)&revision+len-4;
|
||||
else
|
||||
rev = revision;
|
||||
// get last four characters (ignore preceeding 1000 for overvolt)
|
||||
if (len > 4) {
|
||||
rev = (char *)&revision+len-4;
|
||||
} else {
|
||||
rev = revision;
|
||||
}
|
||||
|
||||
if ((strcmp(rev, "0002") == 0) ||
|
||||
(strcmp(rev, "0003") == 0)) {
|
||||
info->type = "Model B";
|
||||
info->p1_revision = 1;
|
||||
info->ram = "256M";
|
||||
info->processor = "BCM2835";
|
||||
} else if (strcmp(rev, "0004") == 0) {
|
||||
info->type = "Model B";
|
||||
info->p1_revision = 2;
|
||||
info->ram = "256M";
|
||||
info->manufacturer = "Sony";
|
||||
info->processor = "BCM2835";
|
||||
} else if (strcmp(rev, "0005") == 0) {
|
||||
info->type = "Model B";
|
||||
info->p1_revision = 2;
|
||||
info->ram = "256M";
|
||||
info->manufacturer = "Qisda";
|
||||
info->processor = "BCM2835";
|
||||
} else if (strcmp(rev, "0006") == 0) {
|
||||
info->type = "Model B";
|
||||
info->p1_revision = 2;
|
||||
info->ram = "256M";
|
||||
info->manufacturer = "Egoman";
|
||||
info->processor = "BCM2835";
|
||||
} else if (strcmp(rev, "0007") == 0) {
|
||||
info->type = "Model A";
|
||||
info->p1_revision = 2;
|
||||
info->ram = "256M";
|
||||
info->manufacturer = "Egoman";
|
||||
info->processor = "BCM2835";
|
||||
} else if (strcmp(rev, "0008") == 0) {
|
||||
info->type = "Model A";
|
||||
info->p1_revision = 2;
|
||||
info->ram = "256M";
|
||||
info->manufacturer = "Sony";
|
||||
info->processor = "BCM2835";
|
||||
} else if (strcmp(rev, "0009") == 0) {
|
||||
info->type = "Model A";
|
||||
info->p1_revision = 2;
|
||||
info->ram = "256M";
|
||||
info->manufacturer = "Qisda";
|
||||
info->processor = "BCM2835";
|
||||
} else if (strcmp(rev, "000d") == 0) {
|
||||
info->type = "Model B";
|
||||
info->p1_revision = 2;
|
||||
info->ram = "512M";
|
||||
info->manufacturer = "Egoman";
|
||||
info->processor = "BCM2835";
|
||||
} else if (strcmp(rev, "000e") == 0) {
|
||||
info->type = "Model B";
|
||||
info->p1_revision = 2;
|
||||
info->ram = "512M";
|
||||
info->manufacturer = "Sony";
|
||||
info->processor = "BCM2835";
|
||||
} else if (strcmp(rev, "000f") == 0) {
|
||||
info->type = "Model B";
|
||||
info->p1_revision = 2;
|
||||
info->ram = "512M";
|
||||
info->manufacturer = "Qisda";
|
||||
info->processor = "BCM2835";
|
||||
} else if ((strcmp(rev, "0011") == 0) ||
|
||||
(strcmp(rev, "0014") == 0)) {
|
||||
info->type = "Compute Module";
|
||||
info->p1_revision = 0;
|
||||
info->ram = "512M";
|
||||
info->processor = "BCM2835";
|
||||
} else if (strcmp(rev, "0012") == 0) {
|
||||
info->type = "Model A+";
|
||||
info->p1_revision = 3;
|
||||
info->ram = "256M";
|
||||
info->processor = "BCM2835";
|
||||
} else if ((strcmp(rev, "0010") == 0) ||
|
||||
(strcmp(rev, "0013") == 0)) {
|
||||
info->type = "Model B+";
|
||||
info->p1_revision = 3;
|
||||
info->ram = "512M";
|
||||
info->processor = "BCM2835";
|
||||
} else { // don't know - assume revision 3 p1 connector
|
||||
info->p1_revision = 3;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
if ((strcmp(rev, "0002") == 0) ||
|
||||
(strcmp(rev, "0003") == 0)) {
|
||||
info->type = "Model B";
|
||||
info->p1_revision = 1;
|
||||
info->ram = "256M";
|
||||
info->processor = "BCM2835";
|
||||
} else if (strcmp(rev, "0004") == 0) {
|
||||
info->type = "Model B";
|
||||
info->p1_revision = 2;
|
||||
info->ram = "256M";
|
||||
info->manufacturer = "Sony";
|
||||
info->processor = "BCM2835";
|
||||
} else if (strcmp(rev, "0005") == 0) {
|
||||
info->type = "Model B";
|
||||
info->p1_revision = 2;
|
||||
info->ram = "256M";
|
||||
info->manufacturer = "Qisda";
|
||||
info->processor = "BCM2835";
|
||||
} else if (strcmp(rev, "0006") == 0) {
|
||||
info->type = "Model B";
|
||||
info->p1_revision = 2;
|
||||
info->ram = "256M";
|
||||
info->manufacturer = "Egoman";
|
||||
info->processor = "BCM2835";
|
||||
} else if (strcmp(rev, "0007") == 0) {
|
||||
info->type = "Model A";
|
||||
info->p1_revision = 2;
|
||||
info->ram = "256M";
|
||||
info->manufacturer = "Egoman";
|
||||
info->processor = "BCM2835";
|
||||
} else if (strcmp(rev, "0008") == 0) {
|
||||
info->type = "Model A";
|
||||
info->p1_revision = 2;
|
||||
info->ram = "256M";
|
||||
info->manufacturer = "Sony";
|
||||
info->processor = "BCM2835";
|
||||
} else if (strcmp(rev, "0009") == 0) {
|
||||
info->type = "Model A";
|
||||
info->p1_revision = 2;
|
||||
info->ram = "256M";
|
||||
info->manufacturer = "Qisda";
|
||||
info->processor = "BCM2835";
|
||||
} else if (strcmp(rev, "000d") == 0) {
|
||||
info->type = "Model B";
|
||||
info->p1_revision = 2;
|
||||
info->ram = "512M";
|
||||
info->manufacturer = "Egoman";
|
||||
info->processor = "BCM2835";
|
||||
} else if (strcmp(rev, "000e") == 0) {
|
||||
info->type = "Model B";
|
||||
info->p1_revision = 2;
|
||||
info->ram = "512M";
|
||||
info->manufacturer = "Sony";
|
||||
info->processor = "BCM2835";
|
||||
} else if (strcmp(rev, "000f") == 0) {
|
||||
info->type = "Model B";
|
||||
info->p1_revision = 2;
|
||||
info->ram = "512M";
|
||||
info->manufacturer = "Qisda";
|
||||
info->processor = "BCM2835";
|
||||
} else if ((strcmp(rev, "0011") == 0) ||
|
||||
(strcmp(rev, "0014") == 0)) {
|
||||
info->type = "Compute Module";
|
||||
info->p1_revision = 0;
|
||||
info->ram = "512M";
|
||||
info->processor = "BCM2835";
|
||||
} else if (strcmp(rev, "0012") == 0) {
|
||||
info->type = "Model A+";
|
||||
info->p1_revision = 3;
|
||||
info->ram = "256M";
|
||||
info->processor = "BCM2835";
|
||||
} else if ((strcmp(rev, "0010") == 0) ||
|
||||
(strcmp(rev, "0013") == 0)) {
|
||||
info->type = "Model B+";
|
||||
info->p1_revision = 3;
|
||||
info->ram = "512M";
|
||||
info->processor = "BCM2835";
|
||||
} else { // don't know - assume revision 3 p1 connector
|
||||
info->p1_revision = 3;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -28,14 +28,13 @@ SOFTWARE.
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int p1_revision;
|
||||
char *ram;
|
||||
char *manufacturer;
|
||||
char *processor;
|
||||
char *type;
|
||||
char revision[1024];
|
||||
typedef struct {
|
||||
int p1_revision;
|
||||
char *ram;
|
||||
char *manufacturer;
|
||||
char *processor;
|
||||
char *type;
|
||||
char revision[1024];
|
||||
} rpi_info;
|
||||
|
||||
int get_rpi_info(rpi_info *info);
|
||||
|
||||
@@ -35,14 +35,15 @@
|
||||
|
||||
int piHiPri (const int pri)
|
||||
{
|
||||
struct sched_param sched ;
|
||||
struct sched_param sched ;
|
||||
|
||||
memset (&sched, 0, sizeof(sched)) ;
|
||||
memset (&sched, 0, sizeof(sched)) ;
|
||||
|
||||
if (pri > sched_get_priority_max (SCHED_RR))
|
||||
sched.sched_priority = sched_get_priority_max (SCHED_RR) ;
|
||||
else
|
||||
sched.sched_priority = pri ;
|
||||
if (pri > sched_get_priority_max (SCHED_RR)) {
|
||||
sched.sched_priority = sched_get_priority_max (SCHED_RR) ;
|
||||
} else {
|
||||
sched.sched_priority = pri ;
|
||||
}
|
||||
|
||||
return sched_setscheduler (0, SCHED_RR, &sched) ;
|
||||
return sched_setscheduler (0, SCHED_RR, &sched) ;
|
||||
}
|
||||
|
||||
+43
-25
@@ -55,8 +55,7 @@ static pthread_t *threadIds[64] = {NULL};
|
||||
|
||||
// sysFds:
|
||||
// Map a file descriptor from the /sys/class/gpio/gpioX/value
|
||||
static int sysFds[64] =
|
||||
{
|
||||
static int sysFds[64] = {
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
@@ -82,7 +81,7 @@ int get_gpio_number(uint8_t physPin, uint8_t *gpio)
|
||||
}
|
||||
|
||||
if ((rpiinfo.p1_revision != 3 && physPin > 26)
|
||||
|| (rpiinfo.p1_revision == 3 && physPin > 40)) {
|
||||
|| (rpiinfo.p1_revision == 3 && physPin > 40)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -95,7 +94,8 @@ int get_gpio_number(uint8_t physPin, uint8_t *gpio)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *interruptHandler(void *args) {
|
||||
void *interruptHandler(void *args)
|
||||
{
|
||||
int fd, ret;
|
||||
struct pollfd polls;
|
||||
char c;
|
||||
@@ -126,7 +126,7 @@ void *interruptHandler(void *args) {
|
||||
// A one character read appars to be enough.
|
||||
// Followed by a seek to reset it.
|
||||
(void)read (fd, &c, 1) ;
|
||||
lseek (fd, 0, SEEK_SET) ;
|
||||
lseek (fd, 0, SEEK_SET) ;
|
||||
// Call user function.
|
||||
pthread_mutex_lock(&intMutex);
|
||||
if (interruptsEnabled) {
|
||||
@@ -142,7 +142,8 @@ void *interruptHandler(void *args) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void rpi_util::pinMode(uint8_t physPin, uint8_t mode) {
|
||||
void rpi_util::pinMode(uint8_t physPin, uint8_t mode)
|
||||
{
|
||||
uint8_t gpioPin;
|
||||
|
||||
if (get_gpio_number(physPin, &gpioPin)) {
|
||||
@@ -158,7 +159,8 @@ void rpi_util::pinMode(uint8_t physPin, uint8_t mode) {
|
||||
}
|
||||
}
|
||||
|
||||
void rpi_util::digitalWrite(uint8_t physPin, uint8_t value) {
|
||||
void rpi_util::digitalWrite(uint8_t physPin, uint8_t value)
|
||||
{
|
||||
uint8_t gpioPin;
|
||||
|
||||
if (get_gpio_number(physPin, &gpioPin)) {
|
||||
@@ -178,7 +180,8 @@ void rpi_util::digitalWrite(uint8_t physPin, uint8_t value) {
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t rpi_util::digitalRead(uint8_t physPin) {
|
||||
uint8_t rpi_util::digitalRead(uint8_t physPin)
|
||||
{
|
||||
uint8_t gpioPin;
|
||||
|
||||
if (get_gpio_number(physPin, &gpioPin)) {
|
||||
@@ -194,7 +197,8 @@ uint8_t rpi_util::digitalRead(uint8_t physPin) {
|
||||
}
|
||||
}
|
||||
|
||||
void rpi_util::attachInterrupt(uint8_t physPin, void (*func)(), uint8_t mode) {
|
||||
void rpi_util::attachInterrupt(uint8_t physPin, void (*func)(), uint8_t mode)
|
||||
{
|
||||
FILE *fd;
|
||||
char fName[40];
|
||||
char c;
|
||||
@@ -220,7 +224,7 @@ void rpi_util::attachInterrupt(uint8_t physPin, void (*func)(), uint8_t mode) {
|
||||
logError("attachInterrupt: Unable to export pin %d for interrupt: %s\n", physPin, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
fprintf(fd, "%d\n", gpioPin);
|
||||
fprintf(fd, "%d\n", gpioPin);
|
||||
fclose(fd);
|
||||
|
||||
// Wait a bit the system to create /sys/class/gpio/gpio<GPIO number>
|
||||
@@ -228,7 +232,8 @@ void rpi_util::attachInterrupt(uint8_t physPin, void (*func)(), uint8_t mode) {
|
||||
|
||||
snprintf(fName, sizeof(fName), "/sys/class/gpio/gpio%d/direction", gpioPin) ;
|
||||
if ((fd = fopen (fName, "w")) == NULL) {
|
||||
fprintf (stderr, "attachInterrupt: Unable to open GPIO direction interface for pin %d: %s\n", physPin, strerror(errno));
|
||||
fprintf (stderr, "attachInterrupt: Unable to open GPIO direction interface for pin %d: %s\n",
|
||||
physPin, strerror(errno));
|
||||
exit(1) ;
|
||||
}
|
||||
fprintf(fd, "in\n") ;
|
||||
@@ -236,18 +241,27 @@ void rpi_util::attachInterrupt(uint8_t physPin, void (*func)(), uint8_t mode) {
|
||||
|
||||
snprintf(fName, sizeof(fName), "/sys/class/gpio/gpio%d/edge", gpioPin) ;
|
||||
if ((fd = fopen(fName, "w")) == NULL) {
|
||||
fprintf (stderr, "attachInterrupt: Unable to open GPIO edge interface for pin %d: %s\n", physPin, strerror(errno));
|
||||
fprintf (stderr, "attachInterrupt: Unable to open GPIO edge interface for pin %d: %s\n", physPin,
|
||||
strerror(errno));
|
||||
exit(1) ;
|
||||
}
|
||||
switch (mode) {
|
||||
case CHANGE: fprintf(fd, "both\n"); break;
|
||||
case FALLING: fprintf(fd, "falling\n"); break;
|
||||
case RISING: fprintf(fd, "rising\n"); break;
|
||||
case NONE: fprintf(fd, "none\n"); break;
|
||||
default:
|
||||
logError("attachInterrupt: Invalid mode\n");
|
||||
fclose(fd);
|
||||
return;
|
||||
case CHANGE:
|
||||
fprintf(fd, "both\n");
|
||||
break;
|
||||
case FALLING:
|
||||
fprintf(fd, "falling\n");
|
||||
break;
|
||||
case RISING:
|
||||
fprintf(fd, "rising\n");
|
||||
break;
|
||||
case NONE:
|
||||
fprintf(fd, "none\n");
|
||||
break;
|
||||
default:
|
||||
logError("attachInterrupt: Invalid mode\n");
|
||||
fclose(fd);
|
||||
return;
|
||||
}
|
||||
fclose(fd);
|
||||
|
||||
@@ -275,7 +289,8 @@ void rpi_util::attachInterrupt(uint8_t physPin, void (*func)(), uint8_t mode) {
|
||||
pthread_create(threadIds[gpioPin], NULL, interruptHandler, (void *)threadArgs);
|
||||
}
|
||||
|
||||
void rpi_util::detachInterrupt(uint8_t physPin) {
|
||||
void rpi_util::detachInterrupt(uint8_t physPin)
|
||||
{
|
||||
uint8_t gpioPin;
|
||||
|
||||
if (get_gpio_number(physPin, &gpioPin)) {
|
||||
@@ -301,22 +316,25 @@ void rpi_util::detachInterrupt(uint8_t physPin) {
|
||||
logError("Unable to unexport pin %d for interrupt\n", gpioPin);
|
||||
exit(1);
|
||||
}
|
||||
fprintf(fp, "%d", gpioPin);
|
||||
fprintf(fp, "%d", gpioPin);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
uint8_t rpi_util::digitalPinToInterrupt(uint8_t physPin) {
|
||||
uint8_t rpi_util::digitalPinToInterrupt(uint8_t physPin)
|
||||
{
|
||||
// No need to convert the pin to gpio, we do it in attachInterrupt().
|
||||
return physPin;
|
||||
}
|
||||
|
||||
void rpi_util::interrupts() {
|
||||
void rpi_util::interrupts()
|
||||
{
|
||||
pthread_mutex_lock(&intMutex);
|
||||
interruptsEnabled = true;
|
||||
pthread_mutex_unlock(&intMutex);
|
||||
}
|
||||
|
||||
void rpi_util::noInterrupts() {
|
||||
void rpi_util::noInterrupts()
|
||||
{
|
||||
pthread_mutex_lock(&intMutex);
|
||||
interruptsEnabled = false;
|
||||
pthread_mutex_unlock(&intMutex);
|
||||
|
||||
@@ -29,7 +29,8 @@ const int pin_to_gpio_rev1[41] = {-1, -1, -1, 0, -1, 1, -1, 4, 14, -1, 15, 17, 1
|
||||
const int pin_to_gpio_rev2[41] = {-1, -1, -1, 2, -1, 3, -1, 4, 14, -1, 15, 17, 18, 27, -1, 22, 23, -1, 24, 10, -1, 9, 25, 11, 8, -1, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
|
||||
const int pin_to_gpio_rev3[41] = {-1, -1, -1, 2, -1, 3, -1, 4, 14, -1, 15, 17, 18, 27, -1, 22, 23, -1, 24, 10, -1, 9, 25, 11, 8, -1, 7, -1, -1, 5, -1, 6, 12, 13, -1, 19, 16, 26, 20, -1, 21 };
|
||||
|
||||
namespace rpi_util {
|
||||
namespace rpi_util
|
||||
{
|
||||
|
||||
typedef enum {
|
||||
LSBFIRST = BCM2835_SPI_BIT_ORDER_LSBFIRST,
|
||||
|
||||
Reference in New Issue
Block a user