epicardium.h 49.9 KB
Newer Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
	/** Uncalibrated magnetometer (**Unimplemented**) */
	BHI160_UNCALIBRATED_MAGNETOMETER   = 7,
	/** Game rotation vector (whatever that is supposed to be) */
	BHI160_GAME_ROTATION_VECTOR        = 8,
	/** Uncalibrated gyroscrope (**Unimplemented**) */
	BHI160_UNCALIBRATED_GYROSCOPE      = 9,
	/** Geomagnetic rotation vector (**Unimplemented**) */
	BHI160_GEOMAGNETIC_ROTATION_VECTOR = 10,
};

1011
1012
1013
1014
enum bhi160_data_type {
	BHI160_DATA_TYPE_VECTOR
};

1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
/**
 * BHI160 Sensor Data Types
 * ------------------------
 */

/**
 * Vector Data.  The scaling of these values is dependent on the chosen dynamic
 * range.  See the individual sensor's documentation for details.
 */
struct bhi160_data_vector {
1025
1026
	enum bhi160_data_type data_type;

1027
1028
1029
1030
1031
1032
	/** X */
	int16_t x;
	/** Y */
	int16_t y;
	/** Z */
	int16_t z;
koalo's avatar
koalo committed
1033
1034
	/** Status */
	uint8_t status;
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
};

/**
 * BHI160 API
 * ----------
 */

/**
 * Configuration for a BHI160 sensor.
 *
 * This struct is used when enabling a sensor using
 * :c:func:`epic_bhi160_enable_sensor`.
 */
struct bhi160_sensor_config {
	/**
	 * Number of samples Epicardium should keep for this sensor.  Do not set
	 * this number too high as the sample buffer will eat RAM.
	 */
	size_t sample_buffer_len;
	/**
	 * Sample rate for the sensor in Hz.  Maximum data rate is limited
	 * to 200 Hz for all sensors though some might be limited at a lower
	 * rate.
	 */
	uint16_t sample_rate;
	/**
	 * Dynamic range.  Interpretation of this value depends on
	 * the sensor type.  Please refer to the specific sensor in
	 * :c:type:`bhi160_sensor_type` for details.
	 */
	uint16_t dynamic_range;
	/** Always zero. Reserved for future parameters. */
	uint8_t _padding[8];
};

/**
 * Enable a BHI160 virtual sensor.  Calling this funciton will instruct the
 * BHI160 to collect data for this specific virtual sensor.  You can then
 * retrieve the samples using :c:func:`epic_stream_read`.
 *
 * :param bhi160_sensor_type sensor_type: Which sensor to enable.
 * :param bhi160_sensor_config* config: Configuration for this sensor.
 * :returns: A sensor descriptor which can be used with
 *    :c:func:`epic_stream_read` or a negative error value:
 *
 *    - ``-EBUSY``:  The BHI160 driver is currently busy with other tasks and
 *      could not be acquired for enabling a sensor.
1082
1083
 *
 * .. versionadded:: 1.4
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
 */
API(API_BHI160_ENABLE, int epic_bhi160_enable_sensor(
	enum bhi160_sensor_type sensor_type,
	struct bhi160_sensor_config *config
));

/**
 * Disable a BHI160 sensor.
 *
 * :param bhi160_sensor_type sensor_type: Which sensor to disable.
1094
1095
 *
 * .. versionadded:: 1.4
1096
1097
1098
1099
1100
 */
API(API_BHI160_DISABLE, int epic_bhi160_disable_sensor(
	enum bhi160_sensor_type sensor_type
));

1101
1102
/**
 * Disable all BHI160 sensors.
1103
1104
 *
 * .. versionadded:: 1.4
1105
1106
1107
 */
API(API_BHI160_DISABLE_ALL, void epic_bhi160_disable_all_sensors());

Rahix's avatar
Rahix committed
1108
/**
Rahix's avatar
Rahix committed
1109
1110
 * Vibration Motor
 * ===============
Rahix's avatar
Rahix committed
1111
1112
1113
1114
1115
1116
1117
 */

/**
 * Turn vibration motor on or off
 *
 * :param status: 1 to turn on, 0 to turn off.
 */
Gerd's avatar
Gerd committed
1118
1119
API(API_VIBRA_SET, void epic_vibra_set(int status));

1120
1121
1122
1123
1124
1125
1126
/**
 * Turn vibration motor on for a given time
 *
 * :param millis: number of milliseconds to run the vibration motor.
 */
API(API_VIBRA_VIBRATE, void epic_vibra_vibrate(int millis));

Gerd's avatar
Gerd committed
1127
1128
1129
/**
 * Display
 * =======
1130
1131
 * The card10 has an LCD screen that can be accessed from user code.
 *
Rahix's avatar
Rahix committed
1132
1133
1134
1135
1136
1137
1138
1139
 * There are two ways to access the display:
 *
 *  - *immediate mode*, where you ask Epicardium to draw shapes and text for
 *    you.  Most functions in this subsection are related to *immediate mode*.
 *  - *framebuffer mode*, where you provide Epicardium with a memory range where
 *    you already drew graphics whichever way you wanted and Epicardium will
 *    copy them to the display.  To use *framebuffer mode*, use the
 *    :c:func:`epic_disp_framebuffer` function.
Gerd's avatar
Gerd committed
1140
1141
 */

Rahix's avatar
Rahix committed
1142
/** Line-Style */
Rahix's avatar
Rahix committed
1143
enum disp_linestyle {
Rahix's avatar
Rahix committed
1144
  /** */
Gerd's avatar
Gerd committed
1145
  LINESTYLE_FULL = 0,
Rahix's avatar
Rahix committed
1146
  /** */
Gerd's avatar
Gerd committed
1147
1148
1149
  LINESTYLE_DOTTED = 1
};

Rahix's avatar
Rahix committed
1150
/** Fill-Style */
Rahix's avatar
Rahix committed
1151
enum disp_fillstyle {
Rahix's avatar
Rahix committed
1152
  /** */
Gerd's avatar
Gerd committed
1153
  FILLSTYLE_EMPTY = 0,
Rahix's avatar
Rahix committed
1154
  /** */
Gerd's avatar
Gerd committed
1155
1156
1157
  FILLSTYLE_FILLED = 1
};

1158
1159
1160
1161
1162
1163
/** Width of display in pixels */
#define DISP_WIDTH 160

/** Height of display in pixels */
#define DISP_HEIGHT 80

Rahix's avatar
Rahix committed
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
/**
 * Framebuffer
 *
 * The frambuffer stores pixels as RGB565, but byte swapped.  That is, for every ``(x, y)`` coordinate, there are two ``uint8_t``\ s storing 16 bits of pixel data.
 *
 * .. todo::
 *
 *    Document (x, y) in relation to chirality.
 *
 * **Example**: Fill framebuffer with red
 *
 * .. code-block:: cpp
 *
 * 	union disp_framebuffer fb;
 * 	uint16_t red = 0b1111100000000000;
 * 	for (int y = 0; y < DISP_HEIGHT; y++) {
 * 		for (int x = 0; x < DISP_WIDTH; x++) {
 * 			fb.fb[y][x][0] = red >> 8;
 * 			fb.fb[y][x][1] = red & 0xFF;
 * 		}
 * 	}
 * 	epic_disp_framebuffer(&fb);
 */
1187
union disp_framebuffer {
Rahix's avatar
Rahix committed
1188
  /** Coordinate based access (as shown in the example above). */
1189
  uint8_t fb[DISP_HEIGHT][DISP_WIDTH][2];
Rahix's avatar
Rahix committed
1190
  /** Raw byte-indexed access. */
1191
1192
1193
  uint8_t raw[DISP_HEIGHT*DISP_WIDTH*2];
};

Gerd's avatar
Gerd committed
1194
1195
1196
1197
/**
 * Locks the display.
 *
 * :return: ``0`` on success or a negative value in case of an error:
Rahix's avatar
Rahix committed
1198
1199
 *
 *    - ``-EBUSY``: Display was already locked from another task.
Gerd's avatar
Gerd committed
1200
1201
1202
1203
1204
1205
1206
 */
API(API_DISP_OPEN, int epic_disp_open());

/**
 * Unlocks the display again.
 *
 * :return: ``0`` on success or a negative value in case of an error:
Rahix's avatar
Rahix committed
1207
1208
 *
 *    - ``-EBUSY``: Display was already locked from another task.
Gerd's avatar
Gerd committed
1209
1210
1211
1212
1213
1214
 */
API(API_DISP_CLOSE, int epic_disp_close());

/**
 * Causes the changes that have been written to the framebuffer
 * to be shown on the display
1215
1216
1217
 * :return: ``0`` on success or a negative value in case of an error:
 *
 *    - ``-EBUSY``: Display was already locked from another task.
Gerd's avatar
Gerd committed
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
 */
API(API_DISP_UPDATE, int epic_disp_update());

/**
 * Prints a string into the display framebuffer
 *
 * :param posx: x position to print to. 0 <= x <= 160
 * :param posy: y position to print to. 0 <= y <= 80
 * :param pString: string to print
 * :param fg: foreground color in rgb565
 * :param bg: background color in rgb565
 * :return: ``0`` on success or a negative value in case of an error:
Rahix's avatar
Rahix committed
1230
1231
 *
 *    - ``-EBUSY``: Display was already locked from another task.
Gerd's avatar
Gerd committed
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
 */
API(API_DISP_PRINT,
    int epic_disp_print(
	    uint16_t posx,
	    uint16_t posy,
	    const char *pString,
	    uint16_t fg,
	    uint16_t bg)
    );

/**
 * Fills the whole screen with one color
 *
 * :param color: fill color in rgb565
 * :return: ``0`` on success or a negative value in case of an error:
Rahix's avatar
Rahix committed
1247
1248
 *
 *    - ``-EBUSY``: Display was already locked from another task.
Gerd's avatar
Gerd committed
1249
1250
1251
 */
API(API_DISP_CLEAR, int epic_disp_clear(uint16_t color));

1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
/**
 * Draws a pixel on the display
 *
 * :param x: x position; 0 <= x <= 160
 * :param y: y position; 0 <= y <= 80
 * :param color: pixel color in rgb565
 * :return: ``0`` on success or a negative value in case of an error:
 *
 *    - ``-EBUSY``: Display was already locked from another task.
 */
API(API_DISP_PIXEL,
    int epic_disp_pixel(
	    uint16_t x,
	    uint16_t y,
	    uint16_t color)
    );

Gerd's avatar
Gerd committed
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
/**
 * Draws a line on the display
 *
 * :param xstart: x starting position; 0 <= x <= 160
 * :param ystart: y starting position; 0 <= y <= 80
 * :param xend: x ending position; 0 <= x <= 160
 * :param yend: y ending position; 0 <= y <= 80
 * :param color: line color in rgb565
 * :param linestyle: 0 for solid, 1 for dottet (almost no visual difference)
 * :param pixelsize: thickness of the line; 1 <= pixelsize <= 8
 * :return: ``0`` on success or a negative value in case of an error:
Rahix's avatar
Rahix committed
1280
1281
 *
 *    - ``-EBUSY``: Display was already locked from another task.
Gerd's avatar
Gerd committed
1282
1283
1284
1285
1286
1287
1288
1289
 */
API(API_DISP_LINE,
    int epic_disp_line(
	    uint16_t xstart,
	    uint16_t ystart,
	    uint16_t xend,
	    uint16_t yend,
	    uint16_t color,
Rahix's avatar
Rahix committed
1290
	    enum disp_linestyle linestyle,
Gerd's avatar
Gerd committed
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
	    uint16_t pixelsize)
    );

/**
 * Draws a rectangle on the display
 *
 * :param xstart: x coordinate of top left corner; 0 <= x <= 160
 * :param ystart: y coordinate of top left corner; 0 <= y <= 80
 * :param xend: x coordinate of bottom right corner; 0 <= x <= 160
 * :param yend: y coordinate of bottom right corner; 0 <= y <= 80
 * :param color: line color in rgb565
 * :param fillstyle: 0 for empty, 1 for filled
 * :param pixelsize: thickness of the rectangle outline; 1 <= pixelsize <= 8
 * :return: ``0`` on success or a negative value in case of an error:
Rahix's avatar
Rahix committed
1305
1306
 *
 *    - ``-EBUSY``: Display was already locked from another task.
Gerd's avatar
Gerd committed
1307
1308
1309
1310
1311
1312
1313
1314
 */
API(API_DISP_RECT,
    int epic_disp_rect(
	    uint16_t xstart,
	    uint16_t ystart,
	    uint16_t xend,
	    uint16_t yend,
	    uint16_t color,
Rahix's avatar
Rahix committed
1315
	    enum disp_fillstyle fillstyle,
Gerd's avatar
Gerd committed
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
	    uint16_t pixelsize)
    );

/**
 * Draws a circle on the display
 *
 * :param x: x coordinate of the center; 0 <= x <= 160
 * :param y: y coordinate of the center; 0 <= y <= 80
 * :param rad: radius of the circle
 * :param color: fill and outline color of the circle (rgb565)
 * :param fillstyle: 0 for empty, 1 for filled
 * :param pixelsize: thickness of the circle outline; 1 <= pixelsize <= 8
 * :return: ``0`` on success or a negative value in case of an error:
Rahix's avatar
Rahix committed
1329
1330
 *
 *    - ``-EBUSY``: Display was already locked from another task.
Gerd's avatar
Gerd committed
1331
1332
1333
1334
1335
1336
1337
 */
API(API_DISP_CIRC,
    int epic_disp_circ(
	    uint16_t x,
	    uint16_t y,
	    uint16_t rad,
	    uint16_t color,
Rahix's avatar
Rahix committed
1338
	    enum disp_fillstyle fillstyle,
Gerd's avatar
Gerd committed
1339
1340
	    uint16_t pixelsize)
    );
1341

1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
/**
 * Immediately send the contents of a framebuffer to the display. This overrides
 * anything drawn by immediate mode graphics and displayed using ``epic_disp_update``.
 *
 * :param fb: framebuffer to display
 * :return: ``0`` on success or negative value in case of an error:
 *
 *    - ``-EBUSY``: Display was already locked from another task.
 */
API(API_DISP_FRAMEBUFFER, int epic_disp_framebuffer(union disp_framebuffer *fb));


1354
1355
1356
/**
 * Set the backlight brightness value
 *
1357
 * :param brightness: brightness from 0 - 100
1358
1359
1360
1361
1362
1363
1364
 * :return: ``0`` on success or negative value in case of an error:
 *
 *    - ``-EBUSY``: Display was already locked from another task.
 */
API(API_DISP_BACKLIGHT, int epic_disp_backlight(uint16_t brightness));


1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
/**
 * Start continuous readout of the light sensor. Will read light level
 * at preconfigured interval and make it available via `epic_light_sensor_get()`.
 *
 * If the continuous readout was already running, this function will silently pass.
 *
 *
 * :return: `0` if the start was successful or a negative error value
 *      if an error occured. Possible errors:
 *
 *      - ``-EBUSY``: The timer could not be scheduled.
 */
API(API_LIGHT_SENSOR_RUN, int epic_light_sensor_run());

/**
 * Get the last light level measured by the continuous readout.
 *
 * :param uint16_t* value: where the last light level should be written.
 * :return: `0` if the readout was successful or a negative error
 *      value. Possible errors:
 *
 *      - ``-ENODATA``: Continuous readout not currently running.
 */
API(API_LIGHT_SENSOR_GET, int epic_light_sensor_get(uint16_t* value));


/**
 * Stop continuous readout of the light sensor.
 *
 * If the continuous readout wasn't running, this function will silently pass.
 *
 * :return: `0` if the stop was sucessful or a negative error value
 *      if an error occured. Possible errors:
 *
 *      - ``-EBUSY``: The timer stop could not be scheduled.
 */
API(API_LIGHT_SENSOR_STOP, int epic_light_sensor_stop());

1403
1404
1405
1406
1407
1408
1409
1410
/**
 * Get the light level directly. Each call has an intrinsic delay of about 240us, I recommend another 100-300us delay via utime.sleep_ms() between calls. Whether or not the IR LED is fast enough is another issue.
 *
 * :return: Light level
 */
API(API_LIGHT_SENSOR_READ, uint16_t epic_light_sensor_read(void));


1411
1412
1413
/**
 * File
 * ====
1414
1415
 * Except for :c:func:`epic_file_open`, which models C stdio's ``fopen``
 * function, ``close``, ``read`` and ``write`` model `close(2)`_, `read(2)`_ and
Rahix's avatar
Rahix committed
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
 * `write(2)`_.  All file-related functions return >= ``0`` on success and
 * ``-Exyz`` on failure, with error codes from errno.h (``EIO``, ``EINVAL``
 * etc.)
 *
 * .. _close(2): http://man7.org/linux/man-pages/man2/close.2.html
 * .. _read(2): http://man7.org/linux/man-pages/man2/read.2.html
 * .. _write(2): http://man7.org/linux/man-pages/man2/write.2.html
 */

/** */
1426
1427
1428
API(API_FILE_OPEN, int epic_file_open(
	const char* filename, const char* modeString
));
Rahix's avatar
Rahix committed
1429

1430
/** */
Rahix's avatar
Rahix committed
1431
API(API_FILE_CLOSE, int epic_file_close(int fd));
Rahix's avatar
Rahix committed
1432
1433

/** */
Rahix's avatar
Rahix committed
1434
API(API_FILE_READ, int epic_file_read(int fd, void* buf, size_t nbytes));
Rahix's avatar
Rahix committed
1435

1436
/**
1437
 * Write bytes to a file.
1438
 *
1439
1440
1441
 * :param int fd: Descriptor returned by :c:func:`epic_file_open`.
 * :param void* buf: Data to write.
 * :param size_t nbytes: Number of bytes to write.
1442
1443
1444
1445
 *
 * :return: ``< 0`` on error, ``nbytes`` on success. (Partial writes don't occur on success!)
 *
*/
Rahix's avatar
Rahix committed
1446
1447
API(
	API_FILE_WRITE,
Rahix's avatar
Rahix committed
1448
	int epic_file_write(int fd, const void* buf, size_t nbytes)
Rahix's avatar
Rahix committed
1449
1450
1451
);

/** */
Rahix's avatar
Rahix committed
1452
API(API_FILE_FLUSH, int epic_file_flush(int fd));
1453

1454
1455
1456
1457
1458
1459
/** */
API(API_FILE_SEEK, int epic_file_seek(int fd, long offset, int whence));

/** */
API(API_FILE_TELL, int epic_file_tell(int fd));

Rahix's avatar
Rahix committed
1460
/** */
1461
enum epic_stat_type {
Rahix's avatar
Rahix committed
1462
1463
1464
1465
1466
1467
	/**
	 * Basically ``ENOENT``. Although :c:func:`epic_file_stat` returns an
	 * error for 'none', the type will still be set to none additionally.
	 *
	 * This is also used internally to track open FS objects, where we use
	 * ``EPICSTAT_NONE`` to mark free objects.
1468
1469
1470
	 */
	EPICSTAT_NONE,
	/** normal file */
Rahix's avatar
Rahix committed
1471
	EPICSTAT_FILE,
1472
	/** directory */
Rahix's avatar
Rahix committed
1473
	EPICSTAT_DIR,
1474
1475
};

1476
1477
1478
1479
1480
/**
 * Maximum length of a path string (=255).
 */
#define EPICSTAT_MAX_PATH        255
/* conveniently the same as FF_MAX_LFN */
1481

Rahix's avatar
Rahix committed
1482
/** */
1483
1484
struct epic_stat {
	/** Entity Type: file, directory or none */
Rahix's avatar
Rahix committed
1485
	enum epic_stat_type type;
Rahix's avatar
Rahix committed
1486
1487
1488
1489
1490
1491
1492
1493
1494

	/*
	 * Note about padding & placement of uint32_t size:
	 *
	 *   To accomodate for future expansion, we want padding at the end of
	 *   this struct. Since sizeof(enum epic_stat_type) can not be assumed
	 *   to be have a certain size, we're placing uint32_t size here so we
	 *   can be sure it will be at offset 4, and therefore the layout of the
	 *   other fields is predictable.
1495
	 */
Rahix's avatar
Rahix committed
1496
1497

	/** Size in bytes. */
1498
	uint32_t size;
Rahix's avatar
Rahix committed
1499

1500
	/** File Name. */
1501
1502
	char name[EPICSTAT_MAX_PATH + 1];
	uint8_t _reserved[12];
1503
};
1504
1505
1506
1507

/**
 * stat path
 *
Rahix's avatar
Rahix committed
1508
 * :param char* filename: path to stat
1509
 * :param epic_stat* stat: pointer to result
1510
 *
Rahix's avatar
Rahix committed
1511
 * :return: ``0`` on success, negative on error
1512
 */
1513
1514
1515
API(API_FILE_STAT, int epic_file_stat(
	const char* path, struct epic_stat* stat
));
1516

1517
/**
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
 * Open a directory, for enumerating its contents.
 *
 * Use :c:func:`epic_file_readdir` to iterate over the directories entries.
 *
 * **Example**:
 *
 * .. code-block:: cpp
 *
 *    #include "epicardium.h"
 *
 *    int fd = epic_file_opendir("/path/to/dir");
 *
 *    struct epic_stat entry;
 *    for (;;) {
 *            epic_file_readdir(fd, &entry);
1533
 *
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
 *            if (entry.type == EPICSTAT_NONE) {
 *                    // End
 *                    break;
 *            }
 *
 *            printf("%s\n", entry.name);
 *    }
 *
 *    epic_file_close(fd);
 *
 * :param char* path: Directory to open.
1545
1546
1547
1548
1549
1550
 *
 * :return: ``> 0`` on success, negative on error
 */
API(API_FILE_OPENDIR, int epic_file_opendir(const char* path));

/**
1551
1552
1553
1554
1555
 * Read one entry from a directory.
 *
 * Call :c:func:`epic_file_readdir` multiple times to iterate over all entries
 * of a directory.  The end of the entry list is marked by returning
 * :c:data:`EPICSTAT_NONE` as the :c:member:`epic_stat.type`.
1556
 *
1557
1558
1559
 * :param int fd: Descriptor returned by :c:func:`epic_file_opendir`.
 * :param epic_stat* stat: Pointer where to store the result.  Pass NULL to
 *    reset iteration offset of ``fd`` back to the beginning.
1560
1561
1562
1563
1564
1565
 *
 * :return: ``0`` on success, negative on error
 */
API(API_FILE_READDIR, int epic_file_readdir(int fd, struct epic_stat* stat));

/**
1566
 * Unlink (remove) a file.
1567
1568
1569
1570
1571
1572
1573
 *
 * :param char* path: file to delete
 *
 * :return: ``0`` on success, negative on error
 */
API(API_FILE_UNLINK, int epic_file_unlink(const char* path));

swym's avatar
swym committed
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
/**
 * Rename a file or directory.
 *
 * :param char* oldp: old name
 * :param char* newp: new name
 *
 * :return: ``0`` on success, negative on error
 */
API(API_FILE_RENAME, int epic_file_rename(const char *oldp, const char* newp));

/**
 * Create directory in CWD
 *
 * :param char* dirname: directory name
 *
 * :return: ``0`` on success, negative on error
 */
API(API_FILE_MKDIR, int epic_file_mkdir(const char *dirname));
1592

1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
/**
 * RTC
 * ===
 */

/**
 * Read the current RTC value.
 *
 * :return: Unix time in seconds
 */
API(API_RTC_GET_SECONDS, uint32_t epic_rtc_get_seconds(void));

1605
/**
Hinerk's avatar
Hinerk committed
1606
 * Read the current RTC value in ms.
1607
1608
1609
1610
1611
 *
 * :return: Unix time in milliseconds
 */
API(API_RTC_GET_MILLISECONDS, uint64_t epic_rtc_get_milliseconds(void));

Hauke Mehrtens's avatar
Hauke Mehrtens committed
1612
1613
1614
1615
1616
/**
 * Sets the current RTC time in milliseconds
 */
API(API_RTC_SET_MILLISECONDS, void epic_rtc_set_milliseconds(uint64_t milliseconds));

Rahix's avatar
Rahix committed
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
/**
 * Schedule the RTC alarm for the given timestamp.
 *
 * :param uint32_t timestamp: When to schedule the IRQ
 * :return: `0` on success or a negative value if an error occured. Possible
 *    errors:
 *
 *    - ``-EINVAL``: RTC is in a bad state
 */
API(API_RTC_SCHEDULE_ALARM, int epic_rtc_schedule_alarm(uint32_t timestamp));

/**
 * **Interrupt Service Routine**
 *
 * ``epic_isr_rtc_alarm()`` is called when the RTC alarm triggers.  The RTC alarm
 * can be scheduled using :c:func:`epic_rtc_schedule_alarm`.
 */
API_ISR(EPIC_INT_RTC_ALARM, epic_isr_rtc_alarm);

1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
/**
 * TRNG
 * ====
 */

/**
 * Read random bytes from the TRNG.
 *
 * :param uint8_t * dest: Destination buffer
 * :param size: Number of bytes to read.
 * :return: `0` on success or a negative value if an error occured. Possible
 *    errors:
 *
 *    - ``-EFAULT``: Invalid destination address.
 */
API(API_TRNG_READ, int epic_trng_read(uint8_t *dest, size_t size));

schneider's avatar
schneider committed
1653
/**
Rahix's avatar
Rahix committed
1654
1655
 * MAX30001
 * ========
schneider's avatar
schneider committed
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
 */

/**
 * Configuration for a MAX30001 sensor.
 *
 * This struct is used when enabling the sensor using
 * :c:func:`epic_max30001_enable_sensor`.
 */
struct max30001_sensor_config {
	/**
	 * Number of samples Epicardium should keep for this sensor.  Do not set
	 * this number too high as the sample buffer will eat RAM.
	 */
	size_t sample_buffer_len;
	/**
	 * Sample rate for the sensor in Hz.
	 */
	uint16_t sample_rate;

	/**
	 * Set to true if the second lead comes from USB-C
	 */
	bool usb;

	/**
	* Set to true if the interal lead bias of the MAX30001 is to be used.
	*/
	bool bias;

	/** Always zero. Reserved for future parameters. */
	uint8_t _padding[8];
};

/**
 * Enable a MAX30001 ecg sensor.  Calling this funciton will instruct the
 * MAX30001 to collect data for this sensor.  You can then
 * retrieve the samples using :c:func:`epic_stream_read`.
 *
 * :param max30001_sensor_config* config: Configuration for this sensor.
 * :returns: A sensor descriptor which can be used with
 *    :c:func:`epic_stream_read` or a negative error value:
 *
 *    - ``-EBUSY``:  The MAX30001 driver is currently busy with other tasks and
 *      could not be acquired for enabling a sensor.
 *
 * .. versionadded:: 1.6
 */
API(API_MAX30001_ENABLE, int epic_max30001_enable_sensor(
	struct max30001_sensor_config *config
));

/**
 * Disable MAX30001
 *
 * .. versionadded:: 1.6
 */
API(API_MAX30001_DISABLE, int epic_max30001_disable_sensor(
void
));

swym's avatar
swym committed
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
/**
 * De-initialize the currently configured USB device (if any)
 *
 */
API(API_USB_SHUTDOWN, int epic_usb_shutdown(void));
/**
 * Configure the USB peripheral to export the internal FLASH
 * as a Mass Storage device
 */
API(API_USB_STORAGE, int epic_usb_storage(void));
/**
 * Configure the USB peripheral to provide card10's stdin/stdout
 * on a USB CDC-ACM device
 */
API(API_USB_CDCACM, int epic_usb_cdcacm(void));
schneider's avatar
schneider committed
1731

Rahix's avatar
Rahix committed
1732
#endif /* _EPICARDIUM_H */
For faster browsing, not all history is shown. View entire blame