Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem app epson mbed msp430 pl tests
wflib.c
00001 /* 00002 Plastic Logic EPD project on MSP430 00003 00004 Copyright (C) 2014 Plastic Logic Limited 00005 00006 This program is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 /* 00020 * wflib.c -- Waveform library management 00021 * 00022 * Authors: 00023 * Guillaume Tucker <guillaume.tucker@plasticlogic.com> 00024 * 00025 */ 00026 00027 #include "wflib.h" 00028 00029 #include <ChaN/ff.h> 00030 #define LOG_TAG "wflib" 00031 #include "utils.h" 00032 00033 #define DATA_BUFFER_LENGTH 256 00034 00035 static int pl_wflib_fatfs_xfer(struct pl_wflib *wflib, pl_wflib_wr_t wr, 00036 void *ctx) 00037 { 00038 FIL *f = wflib->priv; 00039 size_t left = wflib->size; 00040 00041 #ifdef VERBOSE 00042 LOG("pl_wflib_fatfs_xfer()"); 00043 00044 LOG("size: %lu", (unsigned long) left); 00045 LOG("f: %p", f); 00046 LOG("wr: %p", wr); 00047 #endif 00048 00049 if (f_lseek(f, 0) != FR_OK) 00050 return -1; 00051 00052 while (left) { 00053 uint8_t data[DATA_BUFFER_LENGTH]; 00054 const size_t n = min(left, sizeof(data)); 00055 size_t count; 00056 00057 if ((f_read(f, data, n, &count) != FR_OK) || (count != n)) { 00058 LOG("Failed to read from file"); 00059 return -1; 00060 } 00061 00062 if (wr(ctx, data, n)) 00063 return -1; 00064 00065 left -= n; 00066 } 00067 00068 return 0; 00069 } 00070 00071 int pl_wflib_init_fatfs(struct pl_wflib *wflib, int *f, const char *path) 00072 { 00073 if (f_open((FIL *) f, path, FA_READ) != FR_OK) { 00074 LOG("Failed to open wflib: %s", path); 00075 return -1; 00076 } 00077 00078 wflib->xfer = pl_wflib_fatfs_xfer; 00079 wflib->size = f_size((FIL *) f); 00080 wflib->priv = f; 00081 00082 #ifdef VERBOSE 00083 LOG("wflib xfer: %p", wflib->xfer); 00084 LOG("wflib size: %lu", (unsigned long) wflib->size); 00085 LOG("wflib priv: %p", wflib->priv); 00086 00087 LOG("FatFS (%s)", path); 00088 #endif 00089 00090 return 0; 00091 }
Generated on Tue Jul 12 2022 21:14:35 by
