1 #ifndef LIBPROPELLER_MCP3208_H_
2 #define LIBPROPELLER_MCP3208_H_
43 void Start(
const int dataPin,
const int clockPin,
44 const int selectPin,
const int mode = 0xFF,
45 const int dacAPin = -1,
const int dacBPin = -1) {
47 if (dacAPin == -1 && dacBPin == -1) {
49 Startx(dataPin, clockPin, selectPin, mode, 0);
50 }
else if (dacAPin != -1 && dacBPin == -1) {
52 Startx(dataPin, clockPin, selectPin, mode, (dacAPin & 0x1f) | 0x80);
55 Startx(dataPin, clockPin, selectPin, mode,
56 (((dacBPin & 0x1f) | 0x80) << 8) + ((dacAPin & 0x1f) | 0x80));
74 int In(
const int Channel) {
77 int result = Ins[Channel / 2];
80 result = Channel & 0x1 ? result >> 16 : result;
83 return result & 0xFFFF;
93 int Average(
const int Channel,
const int N) {
97 for (
int i = 0; i < N; i++) {
100 sampleTotal +=
In(Channel);
105 return sampleTotal / N;
115 void Out(
const short aOutput,
const short bOutput = -1) {
116 Dacx = aOutput << 16;
117 Dacy = bOutput << 16;
125 int volatile Dacx, Dacy;
127 void Startx(
const int dataPin,
const int clockPin,
128 const int selectPin,
const int mode,
const int Dacmode) {
130 volatile void * asm_reference = NULL;
131 __asm__
volatile (
"mov %[asm_reference], #MCP3208_Entry\n\t"
132 : [asm_reference]
"+r" (asm_reference));
143 Cog = cognew(_load_start_mcp3208_cog, Ins) + 1;
147 #endif // LIBPROPELLER_MCP3208_H_