Added new SPI driver helpers.

Changed the gertboard code to use it
and ran more tests on he Gertboard code.
This commit is contained in:
Gordon Henderson
2012-08-27 20:56:14 +01:00
parent 4666573910
commit 99095e3fa0
7 changed files with 331 additions and 100 deletions

View File

@@ -14,33 +14,63 @@
#include <stdio.h>
#include <stdint.h>
//#include <stdlib.h>
#include <math.h>
#define B_SIZE 200
#undef DO_TIMING
#include <wiringPi.h>
#include <gertboard.h>
int main (void)
{
int angle ;
int h1 ;
double angle ;
int i ;
uint32_t x1 ;
int buffer [B_SIZE] ;
#ifdef DO_TIMING
unsigned int now, then ;
#endif
printf ("Raspberry Pi Gertboard SPI test program\n") ;
if (gertboardSPISetup () == -1)
if (wiringPiSetupSys () < 0)
return -1 ;
if (gertboardSPISetup () < 0)
return 1 ;
// Generate a Sine Wave
for (i = 0 ; i < B_SIZE ; ++i)
{
angle = ((double)i / (double)B_SIZE) * M_PI * 2.0 ;
buffer [i] = (int)rint ((sin (angle)) * 127.0 + 128.0) ;
}
for (;;)
{
for (angle = 0 ; angle < 360 ; ++angle)
{
h1 = (int)rint (sin ((double)angle * M_PI / 180.0) * 127.0 + 128.0) ;
gertboardAnalogWrite (0, h1) ;
#ifdef DO_TIMING
then = millis () ;
#endif
for (i = 0 ; i < B_SIZE ; ++i)
{
gertboardAnalogWrite (0, buffer [i]) ;
#ifndef DO_TIMING
x1 = gertboardAnalogRead (0) ;
gertboardAnalogWrite (1, x1 >> 2) ; // 10-bit A/D, 8-bit D/A
#endif
}
#ifdef DO_TIMING
now = millis () ;
printf ("%4d mS, %9.7f S/sample", now - then, ((double)(now - then) / 1000.0) / (double)B_SIZE) ;
printf (" -> %9.4f samples/sec \n", 1 / (((double)(now - then) / 1000.0) / (double)B_SIZE)) ;
#endif
}
return 0 ;