1 #ifndef LIBPROPELLER_MCP3208_H_ 2 #define LIBPROPELLER_MCP3208_H_ 6 extern char _load_start_mcp3208_cog[];
45 void Start(
const int dataPin,
const int clockPin,
46 const int selectPin,
const int mode = 0xFF,
47 const int dacAPin = -1,
const int dacBPin = -1) {
49 if (dacAPin == -1 && dacBPin == -1) {
51 Startx(dataPin, clockPin, selectPin, mode, 0);
52 }
else if (dacAPin != -1 && dacBPin == -1) {
54 Startx(dataPin, clockPin, selectPin, mode, (dacAPin & 0x1f) | 0x80);
57 Startx(dataPin, clockPin, selectPin, mode,
58 (((dacBPin & 0x1f) | 0x80) << 8) + ((dacAPin & 0x1f) | 0x80));
76 int In(
const int Channel) {
79 int result = Ins[Channel / 2];
82 result = Channel & 0x1 ? result >> 16 : result;
85 return result & 0xFFFF;
95 int Average(
const int Channel,
const int N) {
99 for (
int i = 0; i < N; i++) {
102 sampleTotal +=
In(Channel);
107 return sampleTotal / N;
117 void Out(
const short aOutput,
const short bOutput = -1) {
118 Dacx = aOutput << 16;
119 Dacy = bOutput << 16;
127 int volatile Dacx, Dacy;
129 void Startx(
const int dataPin,
const int clockPin,
130 const int selectPin,
const int mode,
const int Dacmode) {
132 volatile void * asm_reference = NULL;
133 __asm__
volatile (
"mov %[asm_reference], #MCP3208_Entry\n\t" 134 : [asm_reference]
"+r" (asm_reference));
145 Cog = cognew(_load_start_mcp3208_cog, Ins) + 1;
151 #endif // LIBPROPELLER_MCP3208_H_
int In(const int Channel)
int Average(const int Channel, const int N)
void Out(const short aOutput, const short bOutput=-1)
void Start(const int dataPin, const int clockPin, const int selectPin, const int mode=0xFF, const int dacAPin=-1, const int dacBPin=-1)