I would like to know if there is a way to call functions that are contained within C files using an Arduino sketch?
My C file declares and defines a function. To save putting the messy function definition into my Arduino sketch, I'd like to call the function straight from the sketch.
Is there a standard way to do this using Arduino and C? Here is the sketch:
#include "crc16.h";
void setup(){
}
void loop(){
CalculateCRC16("<09M", 4);
}
and this is the trimmed down C file:
#include <stdio.h>
#include <stdint.h>
uint16_t crctable[256] =
{
0x0000, 0x1189,.....
uint16_t // Returns Calculated CRC value
CalculateCRC16( // Call example CalculateCRC16("<09M", 4);
const void *c_ptr, // Pointer to byte array to perform CRC on
size_t len) // Number of bytes to CRC
{
uint16_t crc = 0xFFFF // Seed for CRC calculation
const uint8_t *c = c_ptr;
while (len--)
crc = (crc << 8) ^ crctable[((crc >> 8) ^ *c++)];
return crc;
}