v0.1 board believed to be reading Vbat, Pressure, and X/Y/Z correctly now,
[fw/openalt] / usbmass / mscspi2.c
1 /*****************************************************************************\
2 *              efs - General purpose Embedded Filesystem library              *
3 *          --------------------- -----------------------------------          *
4 *                                                                             *
5 * Filename : lpc2000_spi.c                                                     *
6 * Description : This  contains the functions needed to use efs for        *
7 *               accessing files on an SD-card connected to an LPC2xxx.        *
8 *                                                                             *
9 * This library is free software; you can redistribute it and/or               *
10 * modify it under the terms of the GNU Lesser General Public                  *
11 * License as published by the Free Software Foundation; either                *
12 * version 2.1 of the License, or (at your option) any later version.          *
13 *                                                                             *
14 * This library is distributed in the hope that it will be useful,             *
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of              *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           *
17 * Lesser General Public License for more details.                             *
18 *                                                                             *
19 *                                                    (c)2005 Martin Thomas    *
20 *                                                                             *
21 \*****************************************************************************/
22
23 /*
24   2006, Bertrik Sikken, modified for LPCUSB
25 */
26
27 //
28 //
29 //
30 #include "FreeRTOS.h"
31
32 #include "../fatfs/spi.h"
33
34 #include "mscspi.h"
35
36 //
37 //
38 //
39 #define SELECT_CARD()   do { GPIO0_IOCLR = GPIO_IO_P20; } while (0)
40 #define UNSELECT_CARD() do { GPIO0_IOSET = GPIO_IO_P20; } while (0)
41
42 //
43 //
44 //
45 void mscspiInit (void)
46 {
47   spiInit ();
48 }
49
50 //
51 //
52 //
53 U8 mscspiTransferByte (U8 outgoing)
54 {
55   U8 r;
56
57   SELECT_CARD ();
58   r = spiTransferByte (outgoing);
59   UNSELECT_CARD ();
60
61   return r;
62 }
63
64 //
65 //
66 //
67 void mscspiSendBlock (U8 *pbBuf, int iLen)
68 {
69   SELECT_CARD ();
70   spiSendBlock (pbBuf, iLen);
71   UNSELECT_CARD ();
72 }
73
74 //
75 //
76 //
77 void mscspiReceiveBlock (U8 *pbBuf, int iLen)
78 {
79   SELECT_CARD ();
80   spiReceiveBlock (pbBuf, iLen);
81   UNSELECT_CARD ();
82 }