##// END OF EJS Templates
More cleanup, added subdirectories inside include dir, cleaned include tree,...
jeandet -
r72:6ad096835359 dev_alexis
parent child
Show More
@@ -0,0 +1,72
1 /*------------------------------------------------------------------------------
2 #-- This file is a part of the libuc, microcontroler library
3 #-- Copyright (C) 2011, Alexis Jeandet
4 #--
5 #-- This program is free software; you can redistribute it and/or modify
6 #-- it under the terms of the GNU General Public License as published by
7 #-- the Free Software Foundation; either version 3 of the License, or
8 #-- (at your option) any later version.
9 #--
10 #-- This program is distributed in the hope that it will be useful,
11 #-- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 #-- GNU General Public License for more details.
14 #--
15 #-- You should have received a copy of the GNU General Public License
16 #-- along with this program; if not, write to the Free Software
17 #-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #-------------------------------------------------------------------------------
19 #-- Author : Alexis Jeandet
20 #-- Mail : alexis.jeandet@gmail.com
21 #-------------------------------------------------------------------------------*/
22 #ifndef ADS1278_H
23 #define ADS1278_H
24 #include <uhandle.h>
25
26 typedef void (*set_clkdiv_t)(int val);
27 typedef void (*set_sync_t)(int val);
28 typedef void (*set_mode0_t)(int val);
29 typedef void (*set_mode1_t)(int val);
30 typedef void (*set_fsync_t)(int val);
31 typedef int (*ready_t)();
32
33 struct ads1278Regs
34 {
35 sspDev SSP_device;
36 set_clkdiv_t set_clkdiv;
37 set_sync_t set_sync;
38 set_mode0_t set_mode0;
39 set_mode1_t set_mode1;
40 set_fsync_t set_fsync;
41 ready_t ready;
42 };
43
44 typedef struct ads1278Regs ads1278Dev;
45
46 void ads1278open(ads1278Dev* codec,sspDev dev);
47 void ads1278sample(ads1278Dev* dev);
48 void ads1278readresult(ads1278Dev* dev,unsigned int* CH1,unsigned int* CH2,unsigned int* CH3,unsigned int* CH4,unsigned int* CH5,unsigned int* CH6,unsigned int* CH7,unsigned int* CH8);
49
50 extern void bsp_ads1278_Sample();
51 extern int bsp_ads1278_Ready();
52 extern void bsp_ads1278_Synch();
53
54 #endif
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
@@ -0,0 +1,86
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2011, Alexis Jeandet
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@gmail.com
21 -------------------------------------------------------------------------------*/
22 #ifndef CS43L22_H
23 #define CS43L22_H
24
25 #include <i2c.h>
26
27 typedef struct CS43L22_t
28 {
29 i2c_t i2cdev;
30 uint8_t devAddress;
31 }CS43L22_t;
32
33 extern int cs43l22open(CS43L22_t* dev,i2c_t i2cdev,uint8_t A0);
34 extern uint8_t cs43l22getID(CS43L22_t* dev);
35
36 #define CS43L22_I2C_ADDRESS 0x4a
37
38
39 #define CS43L22_MAP_ID 1
40 #define CS43L22_MAP_Power_Ctl_1 2
41 #define CS43L22_MAP_Power_Ctl_2 4
42 #define CS43L22_MAP_Clocking_Ctl 5
43 #define CS43L22_MAP_Interface_Ctl_1 6
44 #define CS43L22_MAP_Interface_Ctl_2 7
45 #define CS43L22_MAP_Passthrough_A 8
46 #define CS43L22_MAP_Passthrough_B 9
47 #define CS43L22_MAP_Analog_ZC_SR 0xA
48 #define CS43L22_MAP_Passthrough 0xC
49 #define CS43L22_MAP_Playback_Ctl_1 0xD
50 #define CS43L22_MAP_Misc_Ctl 0xE
51 #define CS43L22_MAP_Playback_Ctl_2 0xF
52 #define CS43L22_MAP_Passthrough_A_Vol 0x14
53 #define CS43L22_MAP_Passthrough_B_Vol 0x15
54 #define CS43L22_MAP_PCMA_Vol 0x1A
55 #define CS43L22_MAP_PCMB_Vol 0x1B
56 #define CS43L22_MAP_BEEP_Freq 0x1C
57 #define CS43L22_MAP_BEEP_Vol 0x1d
58 #define CS43L22_MAP_BEEP_Tone_Cfg 0x1E
59 #define CS43L22_MAP_Tone_Ctl 0x1F
60 #define CS43L22_MAP_Master_A_Vol 0x20
61 #define CS43L22_MAP_Master_B_Vol 0x21
62 #define CS43L22_MAP_Headphone_A_Vol 0x22
63 #define CS43L22_MAP_Headphone_B_Vol 0x23
64 #define CS43L22_MAP_Speaker_A_Vol 0x24
65 #define CS43L22_MAP_Speaker_B_Vol 0x25
66 #define CS43L22_MAP_Channel_Mixer 0x26
67 #define CS43L22_MAP_Limit_Ctl_1 0x27
68 #define CS43L22_MAP_Limit Ctl_2 0x28
69 #define CS43L22_MAP_Limiter_Attack 0x29
70 #define CS43L22_MAP_Overflow_And_Clock_Status 0x2E
71 #define CS43L22_MAP_Battery_Compensation 0x2F
72 #define CS43L22_MAP_VP_Battery_Level 0x30
73 #define CS43L22_MAP_Speaker_Status 0x31
74 #define CS43L22_MAP_Temperature_Monitor_Control 0x32
75 #define CS43L22_MAP_Thermal_Foldback 0x33
76 #define CS43L22_MAP_Charge_Pump_Frequency 0x34
77
78
79 #endif
80
81
82
83
84
85
86
@@ -0,0 +1,98
1 /*------------------------------------------------------------------------------
2 #-- This file is a part of the libuc, microcontroler library
3 #-- Copyright (C) 2011, Alexis Jeandet
4 #--
5 #-- This program is free software; you can redistribute it and/or modify
6 #-- it under the terms of the GNU General Public License as published by
7 #-- the Free Software Foundation; either version 3 of the License, or
8 #-- (at your option) any later version.
9 #--
10 #-- This program is distributed in the hope that it will be useful,
11 #-- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 #-- GNU General Public License for more details.
14 #--
15 #-- You should have received a copy of the GNU General Public License
16 #-- along with this program; if not, write to the Free Software
17 #-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #-------------------------------------------------------------------------------
19 #-- Author : Alexis Jeandet
20 #-- Mail : alexis.jeandet@member.fsf.org
21 #-------------------------------------------------------------------------------*/
22 #ifndef VS10XX_H
23 #define VS10XX_H
24 #include <spi.h>
25
26 #define VSMODE 0
27 #define VSSTATUS 1
28 #define VSBASS 2
29 #define VSCLOCKF 3
30 #define VSDECODE_TIME 4
31 #define VSAUDATA 5
32 #define VSWRAM 6
33 #define VSWRAMADDR 7
34 #define VSHDAT0 8
35 #define VSHDAT1 9
36 #define VSAIADDR 0xA
37 #define VSVOL 0xB
38 #define VSAICTRL0 0xC
39 #define VSAICTRL1 0xD
40 #define VSAICTRL2 0xE
41 #define VSAICTRL3 0xF
42
43 // TODO real generic VS10XX driver + plugin and patch loader
44
45 typedef enum VS10XXVER_en
46 {
47 UNKNOWN,
48 VS1001,
49 VS1011,
50 VS1002,
51 VS1003,
52 VS1053,
53 VS1033,
54 VS1103
55 }VS10XXVER_en;
56
57 typedef struct vs10XXDev
58 {
59 spi_t SPIdev;
60 void (*setxCS)(char);
61 void (*setxRST)(char);
62 void (*setxDCS)(char);
63 int (*getDREQ)();
64 VS10XXVER_en VERSION;
65 }vs10XXDev;
66
67
68 void vs10XXopen(vs10XXDev* codec,spi_t dev, void (*setxCS)(char),void (*setxRST)(char),void (*setxDCS)(char),int (*getDREQ)());
69 void vs10XXsoftreset(vs10XXDev* dev);
70 int vs10XXcmdread(vs10XXDev* dev,char address);
71 void vs10XXcmdwrite(vs10XXDev* dev,char address,int value);
72 void vs10XXstream32bytes(vs10XXDev* dev,char* buffer);
73 void vs10XXsetCansel(vs10XXDev* dev);
74 int vs10XXcanselAccepted(vs10XXDev* dev);
75 void vs10XXsoftReset(vs10XXDev* dev);
76 //extern void vs10XXclearXCS();
77 //extern void vs10XXsetXCS();
78 //extern int vs10XXDREQ();
79
80 #endif //VS10XX_H
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
@@ -0,0 +1,55
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2011, Alexis Jeandet
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
21 -------------------------------------------------------------------------------*/
22 #ifndef B24LC0X_H
23 #define B24LC0X_H
24
25 #include <i2c.h>
26
27 typedef struct eeprom24lc0xDev
28 {
29 i2c_t iicdev;
30 unsigned char devAddress;
31 unsigned char size;
32 }eeprom24lc0xDev;
33
34
35
36 extern void eeprom24lc0xopen(eeprom24lc0xDev* dev,i2c_t iicdev,unsigned char A0_A1_A2_val,unsigned int size);
37
38 extern void eeprom24lc0xpagewrite(eeprom24lc0xDev* dev,unsigned char address,unsigned char* page);
39 extern void eeprom24lc0xpageread(eeprom24lc0xDev* dev,unsigned char address,unsigned char* page);
40 extern void eeprom24lc0xbytewrite(eeprom24lc0xDev* dev,unsigned char address,unsigned char data);
41 extern unsigned char eeprom24lc0xbyteread(eeprom24lc0xDev* dev,unsigned char address);
42 extern void eeprom24lc0xreadn(eeprom24lc0xDev* dev,unsigned char address,unsigned char* data, unsigned int count);
43 extern void eeprom24lc0xwriten(eeprom24lc0xDev* dev,unsigned char address,unsigned char* data, unsigned int count);
44
45
46
47
48 #endif
49
50
51
52
53
54
55
@@ -0,0 +1,73
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2013, Alexis Jeandet
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
21 -------------------------------------------------------------------------------*/
22 #ifndef N25Q128_H
23 #define N25Q128_H
24
25 #include <spi.h>
26
27 typedef struct eepromN25Q128Dev
28 {
29 spi_t spidev;
30 void (*select)(int sel);
31 void (*writeprotect)(int wp);
32 void (*holdreset)(int hr);
33 }eepromN25Q128Dev;
34
35 #define N25Q128_PAGE_SZ 256
36 #define N25Q128_CAPACITY_IN_BYTES (1024*1024*16) /*16MB*/
37
38 #define N25Q128_READID 0x9E
39 #define N25Q128_READ 0x03
40 #define N25Q128_FASTREAD 0x0B
41 #define N25Q128_DOFR 0x3B
42 #define N25Q128_DIOFR 0xBB
43 #define N25Q128_QOFR 0x6B
44 #define N25Q128_QIOFR 0xEB
45 #define N25Q128_ROTP 0x4B
46 #define N25Q128_WREN 0x06
47 #define N25Q128_WRDI 0x04
48 #define N25Q128_PP 0x02
49
50
51
52
53
54 extern void eepromN25Q128open(eepromN25Q128Dev* dev,spi_t spidev,void (*select)(int sel),void (*writeprotect)(int wp),void (*holdreset)(int hr));
55 extern void eepromN25Q128pagewrite(eepromN25Q128Dev* dev,uint32_t address,unsigned char* page);
56 extern void eepromN25Q128pageread(eepromN25Q128Dev* dev,uint32_t address,unsigned char* page);
57 extern void eepromN25Q128bytewrite(eepromN25Q128Dev* dev,uint32_t address,unsigned char data);
58 extern unsigned char eepromN25Q128byteread(eepromN25Q128Dev* dev,uint32_t address);
59 extern void eepromN25Q128readn(eepromN25Q128Dev* dev,uint32_t address,unsigned char* data, unsigned int count);
60 extern void eepromN25Q128writen(eepromN25Q128Dev* dev,uint32_t address,unsigned char* data, unsigned int count);
61 extern void eepromN25Q128enablewrite(eepromN25Q128Dev* dev);
62
63
64
65
66 #endif
67
68
69
70
71
72
73
@@ -0,0 +1,62
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2012, Alexis Jeandet
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@gmail.com
21 -------------------------------------------------------------------------------*/
22 #ifndef SDCARD_SDIO_H
23 #define SDCARD_SDIO_H
24 #include <sdcard.h>
25
26 extern void sdcardsdiomake(sdcardDev* sdcard,UHANDLE phy,void (*rcvr_mmc) (UHANDLE,char *,uint32_t ),void (*xmit_mmc) (UHANDLE,const char *,uint32_t ),void (*setspeed) (UHANDLE phy,uint32_t speed),uint32_t (*getspeed) (UHANDLE phy));
27 extern void sdcardsdiomakeblkdev(blkdevice* dev,sdcardDev* sdcard, blkdevselect_t select,blkdevpower_t power,blkdevdetect_t detect,blkdevwriteprotected_t writeprotected);
28
29
30 #endif //SDCARD_SDIO_H
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
@@ -0,0 +1,63
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2012, Alexis Jeandet
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@gmail.com
21 -------------------------------------------------------------------------------*/
22 #ifndef SDCARD_SPI_H
23 #define SDCARD_SPI_H
24 #include <sdcard.h>
25
26
27 extern void sdcardspimake(sdcardDev* sdcard,UHANDLE phy,void (*rcvr_mmc) (UHANDLE,char *,uint32_t ),void (*xmit_mmc) (UHANDLE,const char *,uint32_t ),void (*setspeed) (UHANDLE phy,uint32_t speed),uint32_t (*getspeed) (UHANDLE phy));
28 extern void sdcardspimakeblkdev(blkdevice* dev,sdcardDev* sdcard, blkdevselect_t select,blkdevpower_t power,blkdevdetect_t detect,blkdevwriteprotected_t writeprotected);
29
30
31 #endif
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
@@ -0,0 +1,104
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2012, Alexis Jeandet
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
21 -------------------------------------------------------------------------------*/
22 #ifndef SDCARD_H
23 #define SDCARD_H
24 #include <blkdevice.h>
25
26 /* MMC/SD command */
27 #define CMD0 (0) /* GO_IDLE_STATE */
28 #define CMD1 (1) /* SEND_OP_COND (MMC) */
29 #define ACMD41 (0x80+41) /* SEND_OP_COND (SDC) */
30 #define CMD8 (8) /* SEND_IF_COND */
31 #define CMD9 (9) /* SEND_CSD */
32 #define CMD10 (10) /* SEND_CID */
33 #define CMD12 (12) /* STOP_TRANSMISSION */
34 #define ACMD13 (0x80+13) /* SD_STATUS (SDC) */
35 #define CMD16 (16) /* SET_BLOCKLEN */
36 #define CMD17 (17) /* READ_SINGLE_BLOCK */
37 #define CMD18 (18) /* READ_MULTIPLE_BLOCK */
38 #define CMD23 (23) /* SET_BLOCK_COUNT (MMC) */
39 #define ACMD23 (0x80+23) /* SET_WR_BLK_ERASE_COUNT (SDC) */
40 #define CMD24 (24) /* WRITE_BLOCK */
41 #define CMD25 (25) /* WRITE_MULTIPLE_BLOCK */
42 #define CMD32 (32) /* ERASE_ER_BLK_START */
43 #define CMD33 (33) /* ERASE_ER_BLK_END */
44 #define CMD38 (38) /* ERASE */
45 #define CMD55 (55) /* APP_CMD */
46 #define CMD58 (58) /* READ_OCR */
47
48 /* Card type flags (CardType) */
49 #define CT_MMC 0x01 /* MMC ver 3 */
50 #define CT_SD1 0x02 /* SD ver 1 */
51 #define CT_SD2 0x04 /* SD ver 2 */
52 #define CT_SDC (CT_SD1|CT_SD2) /* SD */
53 #define CT_BLOCK 0x08 /* Block addressing */
54
55 struct sdcard_str
56 {
57 UHANDLE phy;
58 int (*rcvr_mmc) (UHANDLE phy,char *buff,uint32_t bc);
59 int (*xmit_mmc) (UHANDLE phy,const char *buff,uint32_t bc);
60 int (*setspeed) (UHANDLE phy,uint32_t speed);
61 uint32_t (*getspeed) (UHANDLE phy);
62 DSTATUS Stat;
63 char CardType;
64 };
65
66 typedef volatile struct sdcard_str sdcardDev;
67
68 //extern void sdcardmake(sdcardDev* sdcard,UHANDLE phy,void (*rcvr_mmc) (UHANDLE,char *,uint32_t ),void (*xmit_mmc) (UHANDLE,const char *,uint32_t ),void (*setspeed) (UHANDLE phy,uint32_t speed),uint32_t (*getspeed) (UHANDLE phy));
69 //extern void sdcardmakeblkdev(blkdevice* dev,sdcardDev* sdcard, blkdevselect_t select,blkdevpower_t power,blkdevdetect_t detect,blkdevwriteprotected_t writeprotected);
70
71
72 #endif
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
@@ -0,0 +1,128
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2012, Alexis Jeandet
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@gmail.com
21 -------------------------------------------------------------------------------*/
22 #ifndef BLKDEVICE_H
23 #define BLKDEVICE_H
24 #include <uhandle.h>
25 /* Disk Status Bits (DSTATUS) */
26
27 #define STA_NOINIT 0x01 /* Drive not initialized */
28 #define STA_NODISK 0x02 /* No medium in the drive */
29 #define STA_PROTECT 0x04 /* Write protected */
30
31
32 /* Command code for disk_ioctrl fucntion */
33 /* Generic ioctl command (defined for FatFs) */
34 #define CTRL_SYNC 0 /* Flush disk cache (for write functions) */
35 #define GET_SECTOR_COUNT 1 /* Get media size (for only f_mkfs()) */
36 #define GET_SECTOR_SIZE 2 /* Get sector size (for multiple sector size (_MAX_SS >= 1024)) */
37 #define GET_BLOCK_SIZE 3 /* Get erase block size (for only f_mkfs()) */
38 #define CTRL_ERASE_SECTOR 4 /* Force erased a block of sectors (for only _USE_ERASE) */
39
40 /* Generic ioctl command */
41 #define CTRL_POWER 5 /* Get/Set power status */
42 #define CTRL_LOCK 6 /* Lock/Unlock media removal */
43 #define CTRL_EJECT 7 /* Eject media */
44
45 /* MMC/SDC specific ioctl command */
46 #define MMC_GET_TYPE 10 /* Get card type */
47 #define MMC_GET_CSD 11 /* Get CSD */
48 #define MMC_GET_CID 12 /* Get CID */
49 #define MMC_GET_OCR 13 /* Get OCR */
50 #define MMC_GET_SDSTAT 14 /* Get SD status */
51
52 /* ATA/CF specific ioctl command */
53 #define ATA_GET_REV 20 /* Get F/W revision */
54 #define ATA_GET_MODEL 21 /* Get model name */
55 #define ATA_GET_SN 22 /* Get serial number */
56
57 /* NAND specific ioctl command */
58 #define NAND_FORMAT 30 /* Create physical format */
59
60 /* Status of Disk Functions */
61 typedef unsigned char DSTATUS;
62
63 /* Results of Disk Functions */
64 typedef enum {
65 RES_OK = 0, /* 0: Successful */
66 RES_ERROR, /* 1: R/W Error */
67 RES_WRPRT, /* 2: Write Protected */
68 RES_NOTRDY, /* 3: Not Ready */
69 RES_PARERR /* 4: Invalid Parameter */
70 } DRESULT;
71
72 typedef volatile struct blkdevice* blkdeviceptr;
73
74 typedef void (*blkdevselect_t)(char) ;
75 typedef void (*blkdevpower_t)(char) ;
76 typedef char (*blkdevdetect_t)() ;
77 typedef char (*blkdevwriteprotected_t)() ;
78 typedef DRESULT (*blkdevwrite_t)(blkdeviceptr _this,const char *buff,unsigned long sector,char count) ;
79 typedef DRESULT (*blkdevread_t)(blkdeviceptr _this,char *buff,unsigned long sector,char count) ;
80 typedef DRESULT (*blkdevioctl_t)(blkdeviceptr _this,char ctrl,void *buff) ;
81 typedef DSTATUS (*blkdevinitialize_t)(blkdeviceptr _this) ;
82 typedef DSTATUS (*blkdevstatus_t) (blkdeviceptr _this) ;
83
84 typedef struct blkdevice
85 {
86 UHANDLE phy;
87 unsigned int size;
88 unsigned int MaxSpeed;
89 unsigned char Version;
90 blkdevselect_t select;
91 blkdevpower_t power;
92 blkdevdetect_t detect;
93 blkdevwriteprotected_t writeprotected;
94 blkdevwrite_t write;
95 blkdevread_t read;
96 blkdevioctl_t ioctl;
97 blkdevinitialize_t initialize;
98 blkdevstatus_t status;
99 }blkdevice;
100
101
102
103
104
105
106 #endif
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
@@ -0,0 +1,194
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2012, Alexis Jeandet
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
21 -------------------------------------------------------------------------------*/
22 #ifndef FAT32_H
23 #define FAT32_H
24 #include <mbr.h>
25 #include <libucfs.h>
26 #include <ucdirent.h>
27 //#include <stdint.h>
28 /*BPB (Boot Sector) Offsets */
29
30 #define BS_jmpBootoff 0
31 #define BS_OEMNameoff 3
32 #define BPB_BytsPerSecoff 11
33 #define BPB_SecPerClusoff 13
34 #define BPB_RsvdSecCntoff 14
35 #define BPB_NumFATsoff 16
36 #define BPB_RootEntCntoff 17
37 #define BPB_TotSec16off 19
38 #define BPB_Mediaoff 21
39 #define BPB_FATSz16off 22
40 #define BPB_SecPerTrkoff 24
41 #define BPB_NumHeadsoff 26
42 #define BPB_HiddSecoff 28
43 #define BPB_TotSec32off 32
44 /*FAT16*/
45 #define BS_DrvNumFAT16off 36
46 #define BS_Reserved1FAT16off 37
47 #define BS_BootSigFAT16off 38
48 #define BS_VolIDFAT16off 39
49 #define BS_VolLabFAT16off 43
50 #define BS_FilSysTypeFAT16off 54
51 /*FAT32*/
52 #define BPB_FATSz32off 36
53 #define BPB_ExtFlagsoff 40
54 #define BPB_FSVeroff 42
55 #define BPB_RootClusoff 44
56 #define BPB_FSInfooff 48
57 #define BPB_BkBootSecoff 50
58 #define BPB_Reservedoff 52
59 #define BS_DrvNumFAT32off 64
60 #define BS_Reserved1FAT32off 65
61 #define BS_BootSigFAT32off 66
62 #define BS_VolIDFAT32off 67
63 #define BS_VolLabFAT32off 71
64 #define BS_FilSysTypeFAT32off 82
65
66
67 #define DIR_Nameoff 0
68 #define DIR_Attroff 0xb
69 #define DIR_FstClusHIoff 0x14
70 #define DIR_FstClusLOoff 0x1A
71 #define DIR_FileSizeoff 0x1c
72 #define DIR_CrtTimeTenthoff 13
73 #define DIR_CrtTimeoff 14
74 #define DIR_CrtDateoff 16
75 #define DIR_LstAccDateoff 18
76 #define DIR_WrtTimeoff 22
77 #define DIR_WrtDateoff 24
78
79
80
81 #define FATBadpart 1
82 #define FATBabArg 2
83 #define FATReadErr 3
84 #define FATnoErr 0
85
86 /*
87 TODO :
88 intergrate a per BLKDEV or per partition buffer.
89 */
90 typedef struct FAT32fs
91 {
92 uint16_t BPB_BytsPerSec;
93 uint16_t BPB_RsvdSecCnt;
94 uint32_t BPB_FATSz32;
95 uint32_t BPB_RootClus;
96 uint32_t fat_begin_lba;
97 uint32_t cluster_begin_lba;
98 uint8_t BPB_SecPerClus;
99 uint8_t BPB_NumFATs;
100 char valide;
101 dikpartition* part;
102 }FAT32fs;
103
104
105 #define castUI64(val) ((uint64_t)(val))
106 #define castUI32(val) ((uint32_t)(val))
107 #define castUI16(val) ((uint16_t)(val))
108 #define castUI8(val) ((uint8_t)(val))
109
110 #define castI64(val) ((int64_t)(val))
111 #define castI32(val) ((int32_t)(val))
112 #define castI16(val) ((int16_t)(val))
113 #define castI8(val) ((int8_t)(val))
114
115 /*
116 TODO :
117 Should add global function for casting with endianness care.
118 have a look at REV, REV16, REVSH, and RBIT ARMV7m asm
119 */
120
121 #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
122 #define fat32Ui8_2_Ui32(table,lsBindex) ((uint32_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint32_t)table[lsBindex+1])<<8))+(0xFF0000&(((uint32_t)table[lsBindex+2])<<16))+(0xFF000000&(((uint32_t)table[lsBindex+3])<<24))))
123 #define fat32Ui8_2_Ui16(table,lsBindex) ((uint16_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint16_t)table[lsBindex+1])<<8))))
124 #define fat32extract16b(table, LSBOffset) (uint16_t)(( (uint16_t) ((uint8_t)table[(LSBOffset)]) ) + (uint16_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 ))
125 #define fat32extract32b(table, LSBOffset) (uint32_t)(( (uint32_t) ((uint8_t)table[(LSBOffset)]) ) + (uint32_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+2]) << 16 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+3]) << 24 ))
126 #else
127 #define fat32Ui8_2_Ui32(table,lsBindex) ((uint32_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint32_t)table[lsBindex+1])<<8))+(0xFF0000&(((uint32_t)table[lsBindex+2])<<16))+(0xFF000000&(((uint32_t)table[lsBindex+3])<<24))))
128 #define fat32Ui8_2_Ui16(table,lsBindex) ((uint16_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint16_t)table[lsBindex+1])<<8))))
129 #define fat32extract16b(table, LSBOffset) (uint16_t)(( (uint16_t) ((uint8_t)table[(LSBOffset)]) ) + (uint16_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 ))
130 #define fat32extract32b(table, LSBOffset) (uint32_t)(( (uint32_t) ((uint8_t)table[(LSBOffset)]) ) + (uint32_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+2]) << 16 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+3]) << 24 ))
131 #endif
132
133
134 /* Get the first sector lba of given cluster number*/
135 #define clusterlba(fs,cluster_number) ((uint32_t)fs->cluster_begin_lba + (((uint32_t)cluster_number) - (2)) * (uint32_t)fs->BPB_SecPerClus)
136
137 //#define fat32clusterinfatsect(fs,cluster_number) ((((uint32_t)(cluster_number))>>6) + fs->fat_begin_lba)
138 #define fat32clusterinfatsect(fs,cluster_number) ((((uint32_t)(cluster_number))>>7) + fs->fat_begin_lba)
139 #define fat32clusterinfatoff(cluster_number) (((cluster_number)&0x7F)*4)
140
141 /*Get cluster index in FAT Table from sector address*/
142 #define fat32masksectorlba(sectorlba,fs) (sectorlba)//(sectorlba & (castUI32(-1)^castUI32(fs->BPB_SecPerClus-1)))
143 #define fat32sectorlbatoclusternum(fs,sectorlba) (((fat32masksectorlba(castUI32(sectorlba),fs) -(castUI32(fs->cluster_begin_lba)))/castUI32(fs->BPB_SecPerClus))+castUI32(2))
144
145
146 #ifdef FAT32_PRIVATE
147 #define fat32sectorreadout(fs,fatsec) \
148 if((lastSecAddrs!=(fatsec)) || (lastFATFS!=(fs))) /*Check if sector already buffered*/ \
149 {\
150 if((fs)->part->phy->read((fs)->part->phy,fat32buff,(fatsec),1)!=RES_OK) \
151 {\
152 return DIRENT_ReadErr;\
153 }\
154 }\
155 lastSecAddrs=(fatsec);\
156 lastFATFS=(fs);
157 #endif
158
159 extern int fat32open(FAT32fs* fs,dikpartition* part);
160 extern int fat32mkdirent(FAT32fs* fs,ucdirent* dirent);
161 extern int fat32getVolName(FAT32fs* fs,char* Name);
162 extern int fat32getrootfirstent(ucdirent* entry);
163 extern int fat32nextdirent(ucdirent* entry);
164 extern int fat32nextsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t* nextsector_lba);
165 extern int fat32prevsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba);
166 extern int fat32prevsectorlba2(FAT32fs* fs,ucdirent* entry,uint32_t lastsector_lba,uint32_t *nextsector_lba);
167 extern uint32_t fat32getdirentlba(ucdirent* entry);
168 extern int fat32getdirentname(ucdirent* entry,char* nameBuffer);
169
170 #endif
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
@@ -0,0 +1,77
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2012, Alexis Jeandet
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@gmail.com
21 -------------------------------------------------------------------------------*/
22 #ifndef FS_H
23 #define FS_H
24 #include <blkdevice.h>
25
26 struct fs_str
27 {
28 UHANDLE fat;
29 };
30
31 typedef struct fs_str filesys_t;
32
33
34
35 #endif
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
@@ -0,0 +1,71
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2012, Alexis Jeandet
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
21 -------------------------------------------------------------------------------*/
22 #ifndef MBR_H
23 #define MBR_H
24 #include <blkdevice.h>
25
26 #define BootFlagoffset 0
27 #define TypeCodeoffset 4
28 #define LBABeginoffset 8
29 #define NumOfSecoffset 12
30
31 #define MBRBadMbr 1
32 #define MBRBabArg 2
33 #define MBRReadErr 3
34 #define MBRnoErr 0
35
36 #define isFat32(TypeCode) (((TypeCode)==0x0b)||((TypeCode)==0x0c))
37
38 typedef struct dikpartition
39 {
40 char TypeCode;
41 char valide;
42 unsigned int LBABegin;
43 unsigned int NumOfSec;
44 blkdevice* phy;
45 }dikpartition;
46
47
48 int mbropen(blkdevice* phy,dikpartition* part,char partNum);
49
50
51 #endif
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
@@ -0,0 +1,131
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2012, Alexis Jeandet
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@gmail.com
21 -------------------------------------------------------------------------------*/
22 #ifndef UCDIRENT_H
23 #define UCDIRENT_H
24 #include <blkdevice.h>
25
26
27 #define ATTR_READ_ONLY 0x01
28 #define ATTR_HIDDEN 0x02
29 #define ATTR_SYSTEM 0x04
30 #define ATTR_VOLUME_ID 0x08
31 #define ATTR_DIRECTORY 0x10
32 #define ATTR_ARCHIVE 0x20
33 #define ATTR_LONGNAME 0x0F
34
35 #define DIRENT_EndOfDir 1
36 #define DIRENT_BabArg 2
37 #define DIRENT_ReadErr 3
38 #define DIRENT_LastSect 4
39 #define DIRENT_BadSect 5
40 #define DIRENT_noErr 0
41
42 typedef struct ucdirent* ucdirentptr;
43 typedef int (*getrootfirstent_t)(ucdirentptr entry);
44 typedef int (*nextdirent_t)(ucdirentptr entry);
45 typedef int (*getname_t)(ucdirentptr entry,char* name);
46
47 typedef struct dirent
48 {
49 unsigned char DIR_Name[16];
50 unsigned char DIR_Attr;
51 unsigned char DIR_CrtTimeTenth;
52 unsigned short DIR_CrtTime;
53 unsigned short DIR_CrtDate;
54 unsigned short DIR_LstAccDate;
55 unsigned short DIR_FstClusHI;
56 unsigned short DIR_WrtTime;
57 unsigned short DIR_WrtDate;
58 unsigned short DIR_FstClustLO;
59 unsigned int DIR_FileSize;
60 unsigned int CurrentSec;
61 unsigned char Currententry;
62 UHANDLE fs;
63 getrootfirstent_t getrootfirstent;
64 nextdirent_t nextdirent;
65 getname_t getname;
66 }dirent;
67
68 typedef struct ucdirent{
69 uint8_t DIR_Name[16];
70 uint8_t DIR_Attr;
71 uint8_t DIR_CrtTimeTenth;
72 uint16_t DIR_CrtTime;
73 uint16_t DIR_CrtDate;
74 uint16_t DIR_LstAccDate;
75 uint16_t DIR_FstClusHI;
76 uint16_t DIR_WrtTime;
77 uint16_t DIR_WrtDate;
78 uint16_t DIR_FstClustLO;
79 uint32_t DIR_FileSize;
80 uint32_t CurrentSec;
81 uint8_t Currententry;
82 UHANDLE fs;
83 getrootfirstent_t getrootfirstent;
84 nextdirent_t nextdirent;
85 getname_t getname;
86 }ucdirent;
87
88
89
90 #define direntgetroot(dirent) (dirent).getrootfirstent(&dirent)
91 #define direntgetnext(dirent) (dirent).nextdirent(&dirent)
92
93 #endif
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
@@ -0,0 +1,51
1 /*------------------------------------------------------------------------------
2 #-- This file is a part of the libuc, microcontroler library
3 #-- Copyright (C) 2011, Alexis Jeandet
4 #--
5 #-- This program is free software; you can redistribute it and/or modify
6 #-- it under the terms of the GNU General Public License as published by
7 #-- the Free Software Foundation; either version 3 of the License, or
8 #-- (at your option) any later version.
9 #--
10 #-- This program is distributed in the hope that it will be useful,
11 #-- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 #-- GNU General Public License for more details.
14 #--
15 #-- You should have received a copy of the GNU General Public License
16 #-- along with this program; if not, write to the Free Software
17 #-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #-------------------------------------------------------------------------------
19 #-- Author : Alexis Jeandet
20 #-- Mail : alexis.jeandet@gmail.com
21 #-------------------------------------------------------------------------------*/
22 #ifndef HEXVIEWER_H
23 #define HEXVIEWER_H
24
25
26
27
28
29 extern void hexviewershow(const char* table,unsigned int size,unsigned int offset);
30
31
32 #endif
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
@@ -0,0 +1,138
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2012, Alexis Jeandet
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@gmail.com
21 -------------------------------------------------------------------------------*/
22 /*
23 */
24
25 #ifndef ADC_H
26 #define ADC_H
27 #include <uhandle.h>
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33
34 typedef struct adc_t
35 {
36 void* _dev;
37 int cfg;
38 int rate;
39 }adc_t;
40
41
42 typedef enum
43 {
44 adc6bits = 0x1,
45 adc7bits = 0x2,
46 adc8bits = 0x3,
47 adc9bits = 0x4,
48 adc10bits = 0x5,
49 adc11bits = 0x6,
50 adc12bits = 0x7,
51 adc13bits = 0x8,
52 adc14bits = 0x9,
53 adc15bits = 0xA,
54 adc16bits = 0xB,
55 adc17bits = 0xC,
56 adc18bits = 0xD,
57 adc19bits = 0xE,
58 adc20bits = 0xF,
59 adc21bits = 0x10,
60 adc22bits = 0x11,
61 adc23bits = 0x12,
62 adc24bits = 0x13
63 }adcbits_t;
64
65 #define ADCBITSMASK 0xF
66
67 typedef enum
68 {
69 adcsingle = 0x00,
70 adcmaster = 0x10
71 }adcconvmode_t;
72
73 #define ADCCONVMODEMASK 0x10
74
75 typedef enum
76 {
77 spiclkinhlow = 0x00,
78 spiclkinhhigh = 0x20
79 }spiclkinhlvl_t;
80
81 #define SPICLKINHLVLMASK 0x20
82
83
84 typedef enum
85 {
86 spiclkfirstedge = 0x00,
87 spiclksecondedge = 0x40
88 }spiclkphase_t;
89
90 #define SPICLKPHASEMASK 0x40
91
92 typedef enum
93 {
94 spimsbfirst = 0x00,
95 spilsbfirst = 0x80
96 }spibitorder_t;
97
98 #define SPIBITORDERMASK 0x80
99
100
101 extern int spiopen(int count,spi_t* spidev);
102 extern int spiopenandconfig(int count,spi_t* spidev,uint32_t cfg,uint32_t speed,uint32_t MOSIpin,uint32_t MISOpin,uint32_t SCKpin,uint32_t SCSpin);
103 extern int spiclose(spi_t* spidev);
104 extern int spisetpins(spi_t* spidev,uint32_t MOSIpin,uint32_t MISOpin,uint32_t SCKpin,uint32_t SCSpin);
105 extern int spienable(spi_t* spidev);
106 extern int spidisable(spi_t* spidev);
107 extern int spisetconfig(spi_t* spidev);
108 extern int spisetspeed(spi_t* spidev, uint32_t speed);
109 extern int spisetbitorder(spi_t* spidev,spibitorder_t order);
110 extern int spisetdatabits(spi_t* spidev,spibits_t bitscnt);
111 extern int spisetclkinhlevel(spi_t* spidev,spiclkinhlvl_t level);
112 extern int spisetclkphase(spi_t* spidev,spiclkphase_t phase);
113 extern int spiputw(spi_t* spidev,uint16_t data);
114 extern uint16_t spigetw(spi_t* spidev);
115 extern int spiputs(spi_t* spidev,char* s);
116 extern int spigets(spi_t* spidev,char* s);
117 extern int spiputnw(spi_t* spidev,uint16_t* w,int n);
118 extern int spigetnw(spi_t* spidev,uint16_t* w,int n);
119 extern int spiputnc(spi_t* spidev,char* c,int n);
120 extern int spigetnc(spi_t* spidev,char* c,int n);
121 extern int spiavailiabledata(spi_t* spidev);
122
123 #ifdef __cplusplus
124 }
125 #endif
126 #endif //ADC_H
127
128
129
130
131
132
133
134
135
136
137
138
This diff has been collapsed as it changes many lines, (590 lines changed) Show them Hide them
@@ -0,0 +1,590
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2012, Alexis Jeandet
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@gmail.com
21 -------------------------------------------------------------------------------*/
22
23 /*! \file gpio.h
24 \brief GPIO api.
25
26 The gpio api gives you a standard way to drive any gpio on any processor.
27 With this api you will be able to open and configure your gpios and set/clear read them.
28
29 A simple example to drive PA0 and read PA1.
30 \code
31 // lets open PA0 and PA1
32 gpio_t mygpio1 gpioopen(PA0);
33 gpioopen(PA1);
34 mygpio1 |= gpiohighspeed | gpiooutdir | gpiopushpulltype | gpionopulltype;
35 gpiosetconfig(mygpio1);
36 //you can also configure with the pin name
37 gpiosetconfig(PA1|gpiohighspeed | gpioindir);
38 //to set PA0
39 gpioset(mygpio1);
40 //to clear it
41 gpioclr(PA0); //PA0 also works and save 4 bytes!
42 //Let read PA1 and write it to PA0
43 gpiosetval(PA0,gpiogetval(PA1));
44 \endcode
45
46 */
47 #ifndef GPIO_H
48 #define GPIO_H
49 #include <stdint.h>
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53
54
55 typedef uint32_t gpio_t;
56
57 typedef enum gpiospeed_t
58 {
59 gpiolowspeed = 0x00000,
60 gpiomediumspeed = 0x10000,
61 gpiofastspeed = 0x20000,
62 gpiohighspeed = 0x30000
63 }gpiospeed_t;
64
65
66
67 typedef enum gpiodir_t
68 {
69 gpioindir = 0x00000,
70 gpiooutdir = 0x40000,
71 gpioaf = 0x80000,
72 gpioan = 0xC0000
73 }gpiodir_t;
74
75
76
77
78 typedef enum gpioouttype_t
79 {
80 gpiopushpulltype = 0x000000,
81 gpioopendraintype = 0x100000
82 }gpioouttype_t;
83
84
85
86 typedef enum gpiopulltype_t
87 {
88 gpionopulltype = 0x000000,
89 gpiopulluptype = 0x200000,
90 gpiopulldowntype = 0x400000
91 }gpiopulltype_t;
92
93 #ifndef DOXYGEN_SHOULD_SKIP_THIS
94 #define GPIOSPEEDMASK 0x30000
95 #define GPIODIRMASK 0xC0000
96 #define GPIOOUTTYPEMASK 0x100000
97 #define GPIOPULLTYPEMASK 0x600000
98 #endif
99
100
101 extern gpio_t gpioopen(uint32_t gpio);
102 extern void gpioclose(gpio_t gpio);
103 extern void gpiosetconfig(gpio_t* gpio);
104 extern void gpiosetdir(gpio_t* gpio,gpiodir_t dir);
105 extern void gpiosetouttype(gpio_t* gpio, gpioouttype_t outtype);
106 extern void gpiosetpulltype(gpio_t* gpio,gpiopulltype_t pulltype);
107 extern void gpiosetspeed(gpio_t* gpio,gpiospeed_t speed);
108 extern void gpioset(gpio_t gpio);
109 extern void gpioclr(gpio_t gpio);
110 extern void gpiosetval(gpio_t gpio,int val);
111 extern int gpiogetval(gpio_t gpio);
112
113 #define GPIOISINPUT(gpio) (((gpio) & GPIODIRMASK)==gpioindir)
114 #define GPIOISOUTPUT(gpio) (((gpio) & GPIOSPEEDMASK)==gpiooutdir)
115
116 #define GPIOISLOWSPEED(gpio) (((gpio) & GPIOSPEEDMASK)==gpiolowspeed)
117 #define GPIOISMEDIUMSPEED(gpio) (((gpio) & GPIOSPEEDMASK)==gpiomediumspeed)
118 #define GPIOISFASTPEED(gpio) (((gpio) & GPIOSPEEDMASK)==gpiofastspeed)
119 #define GPIOISHIGHSPEED(gpio) (((gpio) & GPIOSPEEDMASK)==gpiohighspeeds)
120
121 #define GPIOISPUSHPULL(gpio) (((gpio) & GPIOOUTTYPEMASK)==gpiopushpulltype)
122 #define GPIOISOPENDRAIN(gpio) (((gpio) & GPIOOUTTYPEMASK)==gpioopendraintype)
123
124 #define GPIOISNOPULL(GPIO) (((gpio) & GPIOPULLTYPEMASK)==gpionopulltype)
125 #define GPIOISPULLUP(GPIO) (((gpio) & GPIOPULLTYPEMASK)==gpiopulluptype)
126 #define GPIOISPULLDOWN(GPIO) (((gpio) & GPIOPULLTYPEMASK)==gpiopulldowntype)
127
128 #ifndef DOXYGEN_SHOULD_SKIP_THIS
129
130 #define PA0 ((0<<8)+0)
131 #define PA1 ((0<<8)+1)
132 #define PA2 ((0<<8)+2)
133 #define PA3 ((0<<8)+3)
134 #define PA4 ((0<<8)+4)
135 #define PA5 ((0<<8)+5)
136 #define PA6 ((0<<8)+6)
137 #define PA7 ((0<<8)+7)
138 #define PA8 ((0<<8)+8)
139 #define PA9 ((0<<8)+9)
140 #define PA10 ((0<<8)+10)
141 #define PA11 ((0<<8)+11)
142 #define PA12 ((0<<8)+12)
143 #define PA13 ((0<<8)+13)
144 #define PA14 ((0<<8)+14)
145 #define PA15 ((0<<8)+15)
146 #define PAX ((0<<8)+255)
147 #define PB0 ((1<<8)+0)
148 #define PB1 ((1<<8)+1)
149 #define PB2 ((1<<8)+2)
150 #define PB3 ((1<<8)+3)
151 #define PB4 ((1<<8)+4)
152 #define PB5 ((1<<8)+5)
153 #define PB6 ((1<<8)+6)
154 #define PB7 ((1<<8)+7)
155 #define PB8 ((1<<8)+8)
156 #define PB9 ((1<<8)+9)
157 #define PB10 ((1<<8)+10)
158 #define PB11 ((1<<8)+11)
159 #define PB12 ((1<<8)+12)
160 #define PB13 ((1<<8)+13)
161 #define PB14 ((1<<8)+14)
162 #define PB15 ((1<<8)+15)
163 #define PBX ((1<<8)+255)
164 #define PC0 ((2<<8)+0)
165 #define PC1 ((2<<8)+1)
166 #define PC2 ((2<<8)+2)
167 #define PC3 ((2<<8)+3)
168 #define PC4 ((2<<8)+4)
169 #define PC5 ((2<<8)+5)
170 #define PC6 ((2<<8)+6)
171 #define PC7 ((2<<8)+7)
172 #define PC8 ((2<<8)+8)
173 #define PC9 ((2<<8)+9)
174 #define PC10 ((2<<8)+10)
175 #define PC11 ((2<<8)+11)
176 #define PC12 ((2<<8)+12)
177 #define PC13 ((2<<8)+13)
178 #define PC14 ((2<<8)+14)
179 #define PC15 ((2<<8)+15)
180 #define PCX ((2<<8)+255)
181 #define PD0 ((3<<8)+0)
182 #define PD1 ((3<<8)+1)
183 #define PD2 ((3<<8)+2)
184 #define PD3 ((3<<8)+3)
185 #define PD4 ((3<<8)+4)
186 #define PD5 ((3<<8)+5)
187 #define PD6 ((3<<8)+6)
188 #define PD7 ((3<<8)+7)
189 #define PD8 ((3<<8)+8)
190 #define PD9 ((3<<8)+9)
191 #define PD10 ((3<<8)+10)
192 #define PD11 ((3<<8)+11)
193 #define PD12 ((3<<8)+12)
194 #define PD13 ((3<<8)+13)
195 #define PD14 ((3<<8)+14)
196 #define PD15 ((3<<8)+15)
197 #define PDX ((3<<8)+255)
198 #define PE0 ((4<<8)+0)
199 #define PE1 ((4<<8)+1)
200 #define PE2 ((4<<8)+2)
201 #define PE3 ((4<<8)+3)
202 #define PE4 ((4<<8)+4)
203 #define PE5 ((4<<8)+5)
204 #define PE6 ((4<<8)+6)
205 #define PE7 ((4<<8)+7)
206 #define PE8 ((4<<8)+8)
207 #define PE9 ((4<<8)+9)
208 #define PE10 ((4<<8)+10)
209 #define PE11 ((4<<8)+11)
210 #define PE12 ((4<<8)+12)
211 #define PE13 ((4<<8)+13)
212 #define PE14 ((4<<8)+14)
213 #define PE15 ((4<<8)+15)
214 #define PEX ((4<<8)+255)
215 #define PF0 ((5<<8)+0)
216 #define PF1 ((5<<8)+1)
217 #define PF2 ((5<<8)+2)
218 #define PF3 ((5<<8)+3)
219 #define PF4 ((5<<8)+4)
220 #define PF5 ((5<<8)+5)
221 #define PF6 ((5<<8)+6)
222 #define PF7 ((5<<8)+7)
223 #define PF8 ((5<<8)+8)
224 #define PF9 ((5<<8)+9)
225 #define PF10 ((5<<8)+10)
226 #define PF11 ((5<<8)+11)
227 #define PF12 ((5<<8)+12)
228 #define PF13 ((5<<8)+13)
229 #define PF14 ((5<<8)+14)
230 #define PF15 ((5<<8)+15)
231 #define PFX ((5<<8)+255)
232 #define PG0 ((6<<8)+0)
233 #define PG1 ((6<<8)+1)
234 #define PG2 ((6<<8)+2)
235 #define PG3 ((6<<8)+3)
236 #define PG4 ((6<<8)+4)
237 #define PG5 ((6<<8)+5)
238 #define PG6 ((6<<8)+6)
239 #define PG7 ((6<<8)+7)
240 #define PG8 ((6<<8)+8)
241 #define PG9 ((6<<8)+9)
242 #define PG10 ((6<<8)+10)
243 #define PG11 ((6<<8)+11)
244 #define PG12 ((6<<8)+12)
245 #define PG13 ((6<<8)+13)
246 #define PG14 ((6<<8)+14)
247 #define PG15 ((6<<8)+15)
248 #define PGX ((6<<8)+255)
249 #define PH0 ((7<<8)+0)
250 #define PH1 ((7<<8)+1)
251 #define PH2 ((7<<8)+2)
252 #define PH3 ((7<<8)+3)
253 #define PH4 ((7<<8)+4)
254 #define PH5 ((7<<8)+5)
255 #define PH6 ((7<<8)+6)
256 #define PH7 ((7<<8)+7)
257 #define PH8 ((7<<8)+8)
258 #define PH9 ((7<<8)+9)
259 #define PH10 ((7<<8)+10)
260 #define PH11 ((7<<8)+11)
261 #define PH12 ((7<<8)+12)
262 #define PH13 ((7<<8)+13)
263 #define PH14 ((7<<8)+14)
264 #define PH15 ((7<<8)+15)
265 #define PHX ((7<<8)+255)
266 #define PI0 ((8<<8)+0)
267 #define PI1 ((8<<8)+1)
268 #define PI2 ((8<<8)+2)
269 #define PI3 ((8<<8)+3)
270 #define PI4 ((8<<8)+4)
271 #define PI5 ((8<<8)+5)
272 #define PI6 ((8<<8)+6)
273 #define PI7 ((8<<8)+7)
274 #define PI8 ((8<<8)+8)
275 #define PI9 ((8<<8)+9)
276 #define PI10 ((8<<8)+10)
277 #define PI11 ((8<<8)+11)
278 #define PI12 ((8<<8)+12)
279 #define PI13 ((8<<8)+13)
280 #define PI14 ((8<<8)+14)
281 #define PI15 ((8<<8)+15)
282 #define PIX ((8<<8)+255)
283 #define PJ0 ((9<<8)+0)
284 #define PJ1 ((9<<8)+1)
285 #define PJ2 ((9<<8)+2)
286 #define PJ3 ((9<<8)+3)
287 #define PJ4 ((9<<8)+4)
288 #define PJ5 ((9<<8)+5)
289 #define PJ6 ((9<<8)+6)
290 #define PJ7 ((9<<8)+7)
291 #define PJ8 ((9<<8)+8)
292 #define PJ9 ((9<<8)+9)
293 #define PJ10 ((9<<8)+10)
294 #define PJ11 ((9<<8)+11)
295 #define PJ12 ((9<<8)+12)
296 #define PJ13 ((9<<8)+13)
297 #define PJ14 ((9<<8)+14)
298 #define PJ15 ((9<<8)+15)
299 #define PJX ((9<<8)+255)
300 #define PK0 ((10<<8)+0)
301 #define PK1 ((10<<8)+1)
302 #define PK2 ((10<<8)+2)
303 #define PK3 ((10<<8)+3)
304 #define PK4 ((10<<8)+4)
305 #define PK5 ((10<<8)+5)
306 #define PK6 ((10<<8)+6)
307 #define PK7 ((10<<8)+7)
308 #define PK8 ((10<<8)+8)
309 #define PK9 ((10<<8)+9)
310 #define PK10 ((10<<8)+10)
311 #define PK11 ((10<<8)+11)
312 #define PK12 ((10<<8)+12)
313 #define PK13 ((10<<8)+13)
314 #define PK14 ((10<<8)+14)
315 #define PK15 ((10<<8)+15)
316 #define PKX ((10<<8)+255)
317 #define PL0 ((11<<8)+0)
318 #define PL1 ((11<<8)+1)
319 #define PL2 ((11<<8)+2)
320 #define PL3 ((11<<8)+3)
321 #define PL4 ((11<<8)+4)
322 #define PL5 ((11<<8)+5)
323 #define PL6 ((11<<8)+6)
324 #define PL7 ((11<<8)+7)
325 #define PL8 ((11<<8)+8)
326 #define PL9 ((11<<8)+9)
327 #define PL10 ((11<<8)+10)
328 #define PL11 ((11<<8)+11)
329 #define PL12 ((11<<8)+12)
330 #define PL13 ((11<<8)+13)
331 #define PL14 ((11<<8)+14)
332 #define PL15 ((11<<8)+15)
333 #define PLX ((11<<8)+255)
334 #define PM0 ((12<<8)+0)
335 #define PM1 ((12<<8)+1)
336 #define PM2 ((12<<8)+2)
337 #define PM3 ((12<<8)+3)
338 #define PM4 ((12<<8)+4)
339 #define PM5 ((12<<8)+5)
340 #define PM6 ((12<<8)+6)
341 #define PM7 ((12<<8)+7)
342 #define PM8 ((12<<8)+8)
343 #define PM9 ((12<<8)+9)
344 #define PM10 ((12<<8)+10)
345 #define PM11 ((12<<8)+11)
346 #define PM12 ((12<<8)+12)
347 #define PM13 ((12<<8)+13)
348 #define PM14 ((12<<8)+14)
349 #define PM15 ((12<<8)+15)
350 #define PMX ((12<<8)+255)
351 #define PN0 ((13<<8)+0)
352 #define PN1 ((13<<8)+1)
353 #define PN2 ((13<<8)+2)
354 #define PN3 ((13<<8)+3)
355 #define PN4 ((13<<8)+4)
356 #define PN5 ((13<<8)+5)
357 #define PN6 ((13<<8)+6)
358 #define PN7 ((13<<8)+7)
359 #define PN8 ((13<<8)+8)
360 #define PN9 ((13<<8)+9)
361 #define PN10 ((13<<8)+10)
362 #define PN11 ((13<<8)+11)
363 #define PN12 ((13<<8)+12)
364 #define PN13 ((13<<8)+13)
365 #define PN14 ((13<<8)+14)
366 #define PN15 ((13<<8)+15)
367 #define PNX ((13<<8)+255)
368 #define PO0 ((14<<8)+0)
369 #define PO1 ((14<<8)+1)
370 #define PO2 ((14<<8)+2)
371 #define PO3 ((14<<8)+3)
372 #define PO4 ((14<<8)+4)
373 #define PO5 ((14<<8)+5)
374 #define PO6 ((14<<8)+6)
375 #define PO7 ((14<<8)+7)
376 #define PO8 ((14<<8)+8)
377 #define PO9 ((14<<8)+9)
378 #define PO10 ((14<<8)+10)
379 #define PO11 ((14<<8)+11)
380 #define PO12 ((14<<8)+12)
381 #define PO13 ((14<<8)+13)
382 #define PO14 ((14<<8)+14)
383 #define PO15 ((14<<8)+15)
384 #define POX ((14<<8)+255)
385 #define PP0 ((15<<8)+0)
386 #define PP1 ((15<<8)+1)
387 #define PP2 ((15<<8)+2)
388 #define PP3 ((15<<8)+3)
389 #define PP4 ((15<<8)+4)
390 #define PP5 ((15<<8)+5)
391 #define PP6 ((15<<8)+6)
392 #define PP7 ((15<<8)+7)
393 #define PP8 ((15<<8)+8)
394 #define PP9 ((15<<8)+9)
395 #define PP10 ((15<<8)+10)
396 #define PP11 ((15<<8)+11)
397 #define PP12 ((15<<8)+12)
398 #define PP13 ((15<<8)+13)
399 #define PP14 ((15<<8)+14)
400 #define PP15 ((15<<8)+15)
401 #define PPX ((15<<8)+255)
402 #define PQ0 ((16<<8)+0)
403 #define PQ1 ((16<<8)+1)
404 #define PQ2 ((16<<8)+2)
405 #define PQ3 ((16<<8)+3)
406 #define PQ4 ((16<<8)+4)
407 #define PQ5 ((16<<8)+5)
408 #define PQ6 ((16<<8)+6)
409 #define PQ7 ((16<<8)+7)
410 #define PQ8 ((16<<8)+8)
411 #define PQ9 ((16<<8)+9)
412 #define PQ10 ((16<<8)+10)
413 #define PQ11 ((16<<8)+11)
414 #define PQ12 ((16<<8)+12)
415 #define PQ13 ((16<<8)+13)
416 #define PQ14 ((16<<8)+14)
417 #define PQ15 ((16<<8)+15)
418 #define PQX ((16<<8)+255)
419 #define PR0 ((17<<8)+0)
420 #define PR1 ((17<<8)+1)
421 #define PR2 ((17<<8)+2)
422 #define PR3 ((17<<8)+3)
423 #define PR4 ((17<<8)+4)
424 #define PR5 ((17<<8)+5)
425 #define PR6 ((17<<8)+6)
426 #define PR7 ((17<<8)+7)
427 #define PR8 ((17<<8)+8)
428 #define PR9 ((17<<8)+9)
429 #define PR10 ((17<<8)+10)
430 #define PR11 ((17<<8)+11)
431 #define PR12 ((17<<8)+12)
432 #define PR13 ((17<<8)+13)
433 #define PR14 ((17<<8)+14)
434 #define PR15 ((17<<8)+15)
435 #define PRX ((17<<8)+255)
436 #define PS0 ((18<<8)+0)
437 #define PS1 ((18<<8)+1)
438 #define PS2 ((18<<8)+2)
439 #define PS3 ((18<<8)+3)
440 #define PS4 ((18<<8)+4)
441 #define PS5 ((18<<8)+5)
442 #define PS6 ((18<<8)+6)
443 #define PS7 ((18<<8)+7)
444 #define PS8 ((18<<8)+8)
445 #define PS9 ((18<<8)+9)
446 #define PS10 ((18<<8)+10)
447 #define PS11 ((18<<8)+11)
448 #define PS12 ((18<<8)+12)
449 #define PS13 ((18<<8)+13)
450 #define PS14 ((18<<8)+14)
451 #define PS15 ((18<<8)+15)
452 #define PSX ((18<<8)+255)
453 #define PT0 ((19<<8)+0)
454 #define PT1 ((19<<8)+1)
455 #define PT2 ((19<<8)+2)
456 #define PT3 ((19<<8)+3)
457 #define PT4 ((19<<8)+4)
458 #define PT5 ((19<<8)+5)
459 #define PT6 ((19<<8)+6)
460 #define PT7 ((19<<8)+7)
461 #define PT8 ((19<<8)+8)
462 #define PT9 ((19<<8)+9)
463 #define PT10 ((19<<8)+10)
464 #define PT11 ((19<<8)+11)
465 #define PT12 ((19<<8)+12)
466 #define PT13 ((19<<8)+13)
467 #define PT14 ((19<<8)+14)
468 #define PT15 ((19<<8)+15)
469 #define PTX ((19<<8)+255)
470 #define PU0 ((20<<8)+0)
471 #define PU1 ((20<<8)+1)
472 #define PU2 ((20<<8)+2)
473 #define PU3 ((20<<8)+3)
474 #define PU4 ((20<<8)+4)
475 #define PU5 ((20<<8)+5)
476 #define PU6 ((20<<8)+6)
477 #define PU7 ((20<<8)+7)
478 #define PU8 ((20<<8)+8)
479 #define PU9 ((20<<8)+9)
480 #define PU10 ((20<<8)+10)
481 #define PU11 ((20<<8)+11)
482 #define PU12 ((20<<8)+12)
483 #define PU13 ((20<<8)+13)
484 #define PU14 ((20<<8)+14)
485 #define PU15 ((20<<8)+15)
486 #define PUX ((20<<8)+255)
487 #define PV0 ((21<<8)+0)
488 #define PV1 ((21<<8)+1)
489 #define PV2 ((21<<8)+2)
490 #define PV3 ((21<<8)+3)
491 #define PV4 ((21<<8)+4)
492 #define PV5 ((21<<8)+5)
493 #define PV6 ((21<<8)+6)
494 #define PV7 ((21<<8)+7)
495 #define PV8 ((21<<8)+8)
496 #define PV9 ((21<<8)+9)
497 #define PV10 ((21<<8)+10)
498 #define PV11 ((21<<8)+11)
499 #define PV12 ((21<<8)+12)
500 #define PV13 ((21<<8)+13)
501 #define PV14 ((21<<8)+14)
502 #define PV15 ((21<<8)+15)
503 #define PVX ((21<<8)+255)
504 #define PW0 ((22<<8)+0)
505 #define PW1 ((22<<8)+1)
506 #define PW2 ((22<<8)+2)
507 #define PW3 ((22<<8)+3)
508 #define PW4 ((22<<8)+4)
509 #define PW5 ((22<<8)+5)
510 #define PW6 ((22<<8)+6)
511 #define PW7 ((22<<8)+7)
512 #define PW8 ((22<<8)+8)
513 #define PW9 ((22<<8)+9)
514 #define PW10 ((22<<8)+10)
515 #define PW11 ((22<<8)+11)
516 #define PW12 ((22<<8)+12)
517 #define PW13 ((22<<8)+13)
518 #define PW14 ((22<<8)+14)
519 #define PW15 ((22<<8)+15)
520 #define PWX ((22<<8)+255)
521 #define PX0 ((23<<8)+0)
522 #define PX1 ((23<<8)+1)
523 #define PX2 ((23<<8)+2)
524 #define PX3 ((23<<8)+3)
525 #define PX4 ((23<<8)+4)
526 #define PX5 ((23<<8)+5)
527 #define PX6 ((23<<8)+6)
528 #define PX7 ((23<<8)+7)
529 #define PX8 ((23<<8)+8)
530 #define PX9 ((23<<8)+9)
531 #define PX10 ((23<<8)+10)
532 #define PX11 ((23<<8)+11)
533 #define PX12 ((23<<8)+12)
534 #define PX13 ((23<<8)+13)
535 #define PX14 ((23<<8)+14)
536 #define PX15 ((23<<8)+15)
537 #define PXX ((23<<8)+255)
538 #define PY0 ((24<<8)+0)
539 #define PY1 ((24<<8)+1)
540 #define PY2 ((24<<8)+2)
541 #define PY3 ((24<<8)+3)
542 #define PY4 ((24<<8)+4)
543 #define PY5 ((24<<8)+5)
544 #define PY6 ((24<<8)+6)
545 #define PY7 ((24<<8)+7)
546 #define PY8 ((24<<8)+8)
547 #define PY9 ((24<<8)+9)
548 #define PY10 ((24<<8)+10)
549 #define PY11 ((24<<8)+11)
550 #define PY12 ((24<<8)+12)
551 #define PY13 ((24<<8)+13)
552 #define PY14 ((24<<8)+14)
553 #define PY15 ((24<<8)+15)
554 #define PYX ((24<<8)+255)
555 #define PZ0 ((25<<8)+0)
556 #define PZ1 ((25<<8)+1)
557 #define PZ2 ((25<<8)+2)
558 #define PZ3 ((25<<8)+3)
559 #define PZ4 ((25<<8)+4)
560 #define PZ5 ((25<<8)+5)
561 #define PZ6 ((25<<8)+6)
562 #define PZ7 ((25<<8)+7)
563 #define PZ8 ((25<<8)+8)
564 #define PZ9 ((25<<8)+9)
565 #define PZ10 ((25<<8)+10)
566 #define PZ11 ((25<<8)+11)
567 #define PZ12 ((25<<8)+12)
568 #define PZ13 ((25<<8)+13)
569 #define PZ14 ((25<<8)+14)
570 #define PZ15 ((25<<8)+15)
571 #define PZX ((25<<8)+255)
572
573 #endif
574
575 #ifdef __cplusplus
576 }
577 #endif
578 #endif //GPIO_H
579
580
581
582
583
584
585
586
587
588
589
590
@@ -0,0 +1,72
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2012, Alexis Jeandet
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@gmail.com
21 -------------------------------------------------------------------------------*/
22 #ifndef I2C_H
23 #define I2C_H
24 #include <streamdevices.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 typedef int i2c_t;
31
32 #define i2c1 0
33 #define i2c2 1
34 #define i2c3 2
35 #define i2c4 3
36 #define i2c5 4
37 #define i2c6 5
38 #define i2c7 6
39 #define i2c8 7
40 #define i2c9 8
41
42 extern int i2ctimeout;
43
44 extern i2c_t i2copen(int count);
45 extern i2c_t i2copenandconfig(int count ,uint32_t cfg,uint32_t speed,uint32_t SDA,uint32_t SCL);
46 extern int i2cclose(i2c_t dev);
47 extern int i2csetpins(i2c_t dev,uint32_t SDA,uint32_t SCL);
48 extern int i2cenable(i2c_t dev);
49 extern int i2cdisable(i2c_t dev);
50 //extern int i2csetconfig(i2c_t dev);
51 extern int i2csetspeed(i2c_t dev,uint32_t speed);
52 //extern int i2csetdatabits(i2c_t* dev,uartbits_t databits);
53 extern int i2cwrite(i2c_t dev,char address,char* data,int count);
54 extern int i2cread(i2c_t dev,char address,char* data,int count);
55 extern int i2cbusy(i2c_t dev);
56 extern int i2cStatusCheck(i2c_t dev,int32_t flagMask);
57 #ifdef __cplusplus
58 }
59 #endif
60 #endif //I2C_H
61
62
63
64
65
66
67
68
69
70
71
72
@@ -0,0 +1,150
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2012, Alexis Jeandet
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
21 -------------------------------------------------------------------------------*/
22 /*
23 TODO:
24 Add SPI slave mode
25 Add interrupt interface
26 */
27
28 #ifndef SPI_H
29 #define SPI_H
30 #include <uhandle.h>
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 /*
37 typedef struct spi_t
38 {
39 void* _dev;
40 int cfg;
41 int speed;
42 }spi_t;*/
43
44 typedef int spi_t;
45
46 #define spi1 ((spi_t)0)
47 #define spi2 ((spi_t)1)
48 #define spi3 ((spi_t)2)
49 #define spi4 ((spi_t)3)
50 #define spi5 ((spi_t)4)
51 #define spi6 ((spi_t)5)
52 #define spi7 ((spi_t)6)
53 #define spi8 ((spi_t)7)
54 #define spi9 ((spi_t)8)
55
56
57 typedef enum
58 {
59 spi4bits = 0x3,
60 spi5bits = 0x4,
61 spi6bits = 0x5,
62 spi7bits = 0x6,
63 spi8bits = 0x7,
64 spi9bits = 0x8,
65 spi10bits = 0x9,
66 spi11bits = 0xA,
67 spi12bits = 0xB,
68 spi13bits = 0xC,
69 spi14bits = 0xD,
70 spi15bits = 0xE,
71 spi16bits = 0xF
72 }spibits_t;
73
74 #define SPIBITSMASK 0xF
75
76 typedef enum
77 {
78 spislave = 0x00,
79 spimaster = 0x10
80 }spimode_t;
81
82 #define SPIMODEMASK 0x10
83
84 typedef enum
85 {
86 spiclkinhlow = 0x00,
87 spiclkinhhigh = 0x20
88 }spiclkinhlvl_t;
89
90 #define SPICLKINHLVLMASK 0x20
91
92
93 typedef enum
94 {
95 spiclkfirstedge = 0x00,
96 spiclksecondedge = 0x40
97 }spiclkphase_t;
98
99 #define SPICLKPHASEMASK 0x40
100
101 typedef enum
102 {
103 spimsbfirst = 0x00,
104 spilsbfirst = 0x80
105 }spibitorder_t;
106
107 #define SPIBITORDERMASK 0x80
108
109
110 extern spi_t spiopen(int count);
111 extern spi_t spiopenandconfig(int count,uint32_t cfg,uint32_t speed,uint32_t MOSIpin,uint32_t MISOpin,uint32_t SCKpin,uint32_t SCSpin);
112 extern int spiclose(spi_t spidev);
113 extern int spisetpins(spi_t spidev,uint32_t MOSIpin,uint32_t MISOpin,uint32_t SCKpin,uint32_t SCSpin);
114 extern int spienable(spi_t spidev);
115 extern int spidisable(spi_t spidev);
116 extern int spitransactionfinished(spi_t spidev);
117 extern int spisetconfig(spi_t spidev,uint32_t config,uint32_t speed);
118 extern int spisetspeed(spi_t spidev, uint32_t speed);
119 extern uint32_t spigetspeed(spi_t spidev);
120 extern int spisetbitorder(spi_t spidev,spibitorder_t order);
121 extern int spisetdatabits(spi_t spidev,spibits_t bitscnt);
122 extern int spisetclkinhlevel(spi_t spidev,spiclkinhlvl_t level);
123 extern int spisetclkphase(spi_t spidev,spiclkphase_t phase);
124 extern int spiputw(spi_t spidev,uint16_t data);
125 extern uint16_t spigetw(spi_t spidev);
126 extern uint16_t spigetw2(spi_t spidev,uint16_t data);
127 extern int spiputs(spi_t spidev,char* s);
128 extern int spigets(spi_t spidev,char* s);
129 extern int spiputnw(spi_t spidev,uint16_t* w,int n);
130 extern int spigetnw(spi_t spidev,uint16_t* w,int n);
131 extern int spiputnc(spi_t spidev,char* c,int n);
132 extern int spigetnc(spi_t spidev,char* c,int n);
133 extern int spiavailiabledata(spi_t spidev);
134
135 #ifdef __cplusplus
136 }
137 #endif
138 #endif //SPI_H
139
140
141
142
143
144
145
146
147
148
149
150
@@ -0,0 +1,319
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2012, Alexis Jeandet
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@gmail.com
21 -------------------------------------------------------------------------------*/
22 /*! \file uart.h
23 \brief UART api.
24
25 The uart api gives you a standard way to drive any uart on any processor.
26 With this api you will be able to open and configure your UART define the
27 associated pins when applicable and read/write on it. Note that depending
28 on the target architecture you can have soft or hard UART.
29
30 A simple example to read or writes on uart1.
31 \code
32 // lets open uart1
33 //config :
34 // -parity = No
35 // -data bits = 8
36 // -stop bits = 1
37 // -speed = 115200 bauds
38 // -TX = PA9
39 // -RX = PA10
40 // -CTS = unused (-1)
41 // -RTS = unused (-1)
42 uart_t uart = uartopenandconfig(uart1,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1);
43 //check that everything is ok
44 if(uart==uart1)
45 {
46 //to write 0xFF on uart1
47 uartputc(uart,0xFF);
48 //you can also send a string on uart1
49 char* buffer="hello";
50 uartputs(uart,buffer);
51 //to read a char
52 char result = uartgetc(uart);
53 }
54
55 \endcode
56
57 */
58
59 #ifndef UART_H
60 #define UART_H
61 #include <streamdevices.h>
62
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66
67 /*
68 typedef volatile struct uart_t
69 {
70 volatile void* _dev;
71 volatile int cfg;
72 volatile int speed;
73 }uart_t;
74 */
75
76 /**
77 * @brief uart handle
78 *
79 * uart_t is the handle type you will use for all uart related functions.
80 */
81 typedef int uart_t;
82
83 #define uart1 0 ///< uart1
84 #define uart2 1 ///< uart2
85 #define uart3 2 ///< uart3
86 #define uart4 3 ///< uart4
87 #define uart5 4 ///< uart5
88 #define uart6 5 ///< uart6
89 #define uart7 6 ///< uart7
90 #define uart8 7 ///< uart8
91 #define uart9 8 ///< uart9
92
93 #ifndef DOXYGEN_SHOULD_SKIP_THIS
94 #define UARTPARITYMASK 0x3
95 #define UARTBITSMASK 0xC
96 #define UARTSTOPBITSMASK 0x70
97 #endif
98
99 /**
100 * @brief Uart parity enum
101 *
102 * Use uartparity_t values to configure the parity of your UART port with
103 * uartsetparity function or uartsetconfig. Don't try to use numerical values
104 * directly!
105 */
106 typedef enum uartparity_t
107 {
108 uartparitynone = 0x1, /**< No parity */
109 uartparityeven = 0x2, /**< Even parity */
110 uartparityodd = 0x3 /**< Odd parity */
111 }uartparity_t;
112
113 /**
114 * @brief Uart data bits enum
115 *
116 * Use uartbits_t values to configure the number of data bits of your UART port with
117 * uartsetdatabits function or uartsetconfig. Don't try to use numerical values
118 * directly!
119 */
120 typedef enum uartbits_t
121 {
122 uart7bits = 0x4, /**< 7 data bits communication */
123 uart8bits = 0x8, /**< 8 data bits communication */
124 uart9bits = 0xC /**< 9 data bits communication */
125 }uartbits_t;
126
127 /**
128 * @brief Uart stop bits enum
129 *
130 * Use uartstopbits_t values to configure the number of stop bits of your UART port with
131 * uartsetstopbits function or uartsetconfig. Don't try to use numerical values
132 * directly!
133 */
134 typedef enum uartstopbits_t
135 {
136 uarthalfstop = 0x10, /**< 0.5 stop bits communication */
137 uartonestop = 0x20, /**< 1 stop bits communication */
138 uartonehalfstop = 0x30, /**< 1.5 stop bits communication */
139 uarttwostop = 0x40 /**< 2 stop bits communication */
140 }uartstopbits_t;
141
142
143
144 /**
145 * @brief Uart open function
146 *
147 * This function opens the given uart, it should turn it ON iff needed and enable it.
148 * @param count The uart identifier uart1 for example
149 * @return The uart identifier on success or -1 if it fails.
150 */
151 extern uart_t uartopen(int count);
152 /**
153 * @brief Uart open and configure function
154 *
155 * This function call uartopen and configure the UART with the given parameters.
156 * @param count The uart identifier uart1 for example
157 * @param cfg The configuration of the UART, build from an or mask.
158 * @param speed The target speed of the UART in bauds, the real speed depend on the implementation
159 * and the target.
160 * @param TXpin The TXpin look gpio api.
161 * @param RXpin The RXpin look gpio api.
162 * @param RTSpin The RTSpin look gpio api.
163 * @param CTSpin The CTSpin look gpio api.
164 * @return The uart identifier on success or -1 if it fails.
165 * @sa uartclose(uart_t uart), uartopenandconfig(int count ,uint32_t cfg,uint32_t speed,uint32_t TXpin,uint32_t RXpin,uint32_t RTSpin,uint32_t CTSpin), uartsetconfig(uart_t uart,uint32_t cfg,uint32_t speed)
166 */
167 extern uart_t uartopenandconfig(int count ,uint32_t cfg,uint32_t speed,uint32_t TXpin,uint32_t RXpin,uint32_t RTSpin,uint32_t CTSpin);
168 /**
169 * @brief Uart close function
170 *
171 * This function should at least reset the UART configuration.
172 * @param uart The uart identifier uart1 for example.
173 * @return 1 on success or -1 on error.
174 */
175 extern int uartclose(uart_t uart);
176 /**
177 * @brief uart set pins function
178 *
179 * This function sets the Uart pins, you have to check for each target that the pins you selected
180 * are compatible with the desired function.
181 * @param uart The uart identifier uart1 for example.
182 * @param TXpin The TXpin look gpio api.
183 * @param RXpin The RXpin look gpio api.
184 * @param RTSpin The RTSpin look gpio api.
185 * @param CTSpin The CTSpin look gpio api.
186 * @return 1 on success or -1 on error.
187 * @sa uartopen(int count)
188 */
189 extern int uartsetpins(uart_t uart,uint32_t TXpin,uint32_t RXpin,uint32_t RTSpin,uint32_t CTSpin);
190 /**
191 * @brief Enable uart functionnable
192 *
193 *This function enables given uart, it makes sens on target where you can enable or disable
194 *the uart.
195 * @param uart The uart identifier uart1 for example.
196 * @return 1 on success or -1 on error.
197 * @sa uartenable(uart_t uart)
198 */
199 extern int uartenable(uart_t uart);
200 /**
201 * @brief Disable uart function
202 *
203 *This function disables given uart, it makes sens on target where you can enable or disable
204 *the uart.
205 * @param uart The uart identifier uart1 for example.
206 * @return 1 on success or -1 on error.
207 */
208 extern int uartdisable(uart_t uart);
209 /**
210 * @brief uart set configuration function
211 *
212 * This function configure the given uart.
213 * @param uart The uart identifier uart1 for example.
214 * @param cfg
215 * @param speed
216 * @return
217 */
218 extern int uartsetconfig(uart_t uart,uint32_t cfg,uint32_t speed);
219 /**
220 * @brief uartsetspeed
221 * @param uart The uart identifier uart1 for example.
222 * @param speed
223 * @return
224 */
225 extern int uartsetspeed(uart_t uart,uint32_t speed);
226 /**
227 * @brief uartsetparity
228 * @param uart The uart identifier uart1 for example.
229 * @param parity
230 * @return
231 */
232 extern int uartsetparity(uart_t uart,uartparity_t parity);
233 /**
234 * @brief uartsetdatabits
235 * @param uart The uart identifier uart1 for example.
236 * @param databits
237 * @return
238 */
239 extern int uartsetdatabits(uart_t uart,uartbits_t databits);
240 /**
241 * @brief uartsetstopbits
242 * @param uart The uart identifier uart1 for example.
243 * @param stopbits
244 * @return
245 */
246 extern int uartsetstopbits(uart_t uart,uartstopbits_t stopbits);
247 /**
248 * @brief uartputc
249 * @param uart The uart identifier uart1 for example.
250 * @param c
251 * @return
252 */
253 extern int uartputc(uart_t uart,char c);
254 /**
255 * @brief uartgetc
256 * @param uart The uart identifier uart1 for example.
257 * @return
258 */
259 extern char uartgetc(uart_t uart);
260 /**
261 * @brief uartputs
262 * @param uart The uart identifier uart1 for example.
263 * @param s
264 * @return
265 */
266 extern int uartputs(uart_t uart,char* s);
267 /**
268 * @brief uartgets
269 * @param uart The uart identifier uart1 for example.
270 * @param s
271 * @return
272 */
273 extern int uartgets(uart_t uart,char* s);
274 /**
275 * @brief uartputnc
276 * @param uart The uart identifier uart1 for example.
277 * @param c
278 * @param n
279 * @return
280 */
281 extern int uartputnc(uart_t uart,char* c,int n);
282 /**
283 * @brief uartgetnc
284 * @param uart The uart identifier uart1 for example.
285 * @param c
286 * @param n
287 * @return
288 */
289 extern int uartgetnc(uart_t uart,char* c,int n);
290 /**
291 * @brief uartavailiabledata
292 * @param uart The uart identifier uart1 for example.
293 * @return
294 */
295 extern int uartavailiabledata(uart_t uart);
296 /**
297 * @brief uartmkstreamdev
298 * @param uart The uart identifier uart1 for example.
299 * @param strdev
300 * @return
301 */
302 extern int uartmkstreamdev(uart_t uart,streamdevice* strdev);
303
304 #ifdef __cplusplus
305 }
306 #endif
307 #endif //SPI_H
308
309
310
311
312
313
314
315
316
317
318
319
@@ -0,0 +1,104
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2011, Alexis Jeandet
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@gmail.com
21 -------------------------------------------------------------------------------*/
22 #ifndef INA226_H
23 #define INA226_H
24
25 #include <i2c.h>
26 //#include <uhandle.h>
27
28 typedef struct INA226_t
29 {
30 i2c_t i2cdev;
31 uint8_t devAddress;
32 uint32_t shuntmOhm;
33 uint32_t CurrentRangeuAmp;
34 }INA226_t;
35
36 extern int ina226open(INA226_t* dev,i2c_t i2cdev,uint16_t config,uint8_t A0,uint8_t A1,uint32_t shuntmOhm, uint32_t CurrentRangeuAmp);
37 extern uint16_t ina226getID(INA226_t* dev);
38 extern int ina226calibrate(INA226_t* dev,uint32_t shuntmOhm, uint32_t CurrentRangeuAmp);
39 extern uint32_t ina226getBusVoltage(INA226_t* dev);
40 extern uint32_t ina226getPower(INA226_t* dev);
41 extern int32_t ina226getCurrent(INA226_t* dev);
42 extern uint16_t ina226getReg(INA226_t* dev,char reg);
43 extern int ina226setReg(INA226_t* dev,char reg,int16_t value);
44
45
46 #define INA226_I2C_ADDRESS 0x40
47
48
49 #define INA226_Die_ID_Reg 0xFF
50 #define INA226_Configuration_Reg 0
51 #define INA226_Shunt_Voltage_Reg 1
52 #define INA226_Bus_Voltage_Reg 2
53 #define INA226_Power_Reg 3
54 #define INA226_Current_Reg 4
55 #define INA226_Calibration_Reg 5
56 #define INA226_Mask_Enable_Reg 6
57 #define INA226_Alert_Limit_Reg 7
58
59 #define INA226_AVERAGES_1 0
60 #define INA226_AVERAGES_4 (1<<9)
61 #define INA226_AVERAGES_16 (2<<9)
62 #define INA226_AVERAGES_64 (3<<9)
63 #define INA226_AVERAGES_128 (4<<9)
64 #define INA226_AVERAGES_256 (5<<9)
65 #define INA226_AVERAGES_512 (6<<9)
66 #define INA226_AVERAGES_1024 (7<<9)
67
68 #define INA226_BUS_CONV_140us 0
69 #define INA226_BUS_CONV_204us (1<<6)
70 #define INA226_BUS_CONV_332us (2<<6)
71 #define INA226_BUS_CONV_588us (3<<6)
72 #define INA226_BUS_CONV_1100us (4<<6)
73 #define INA226_BUS_CONV_2116us (5<<6)
74 #define INA226_BUS_CONV_4156us (6<<6)
75 #define INA226_BUS_CONV_8244us (7<<6)
76
77 #define INA226_SHUNT_CONV_140us 0
78 #define INA226_SHUNT_CONV_204us (1<<3)
79 #define INA226_SHUNT_CONV_332us (2<<3)
80 #define INA226_SHUNT_CONV_588us (3<<3)
81 #define INA226_SHUNT_CONV_1100us (4<<3)
82 #define INA226_SHUNT_CONV_2116us (5<<3)
83 #define INA226_SHUNT_CONV_4156us (6<<3)
84 #define INA226_SHUNT_CONV_8244us (7<<3)
85
86 #define INA226_MODE_POWER_DOWN 0
87 #define INA226_MODE_SHUNT_VOLTAGE_TRIGGERRED 1
88 #define INA226_MODE_BUS_VOLTAGE_TRIGGERRED 2
89 #define INA226_MODE_SHUNT_AND_BUS_TRIGGERRED 3
90 #define INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS 5
91 #define INA226_MODE_BUS_VOLTAGE_CONTINUOUS 6
92 #define INA226_MODE_SHUNT_AND_BUS_CONTINUOUS 7
93
94
95
96
97 #endif
98
99
100
101
102
103
104
@@ -52,7 +52,7 PROJECT_LOGO =
52 # If a relative path is entered, it will be relative to the location
52 # If a relative path is entered, it will be relative to the location
53 # where doxygen was started. If left blank the current directory will be used.
53 # where doxygen was started. If left blank the current directory will be used.
54
54
55 OUTPUT_DIRECTORY = /opt/libuc2/Doc/doxygen
55 OUTPUT_DIRECTORY = doc/doxygen
56
56
57 # If the CREATE_SUBDIRS tag is set to YES, then doxygen will create
57 # If the CREATE_SUBDIRS tag is set to YES, then doxygen will create
58 # 4096 sub-directories (in 2 levels) under the output directory of each output
58 # 4096 sub-directories (in 2 levels) under the output directory of each output
@@ -337,7 +337,7 INLINE_SIMPLE_STRUCTS = NO
337 # be useful for C code in case the coding convention dictates that all compound
337 # be useful for C code in case the coding convention dictates that all compound
338 # types are typedef'ed and only the typedef is referenced, never the tag name.
338 # types are typedef'ed and only the typedef is referenced, never the tag name.
339
339
340 TYPEDEF_HIDES_STRUCT = NO
340 TYPEDEF_HIDES_STRUCT = YES
341
341
342 # The SYMBOL_CACHE_SIZE determines the size of the internal cache use to
342 # The SYMBOL_CACHE_SIZE determines the size of the internal cache use to
343 # determine which symbols to keep in memory and which to flush to disk.
343 # determine which symbols to keep in memory and which to flush to disk.
@@ -375,7 +375,7 LOOKUP_CACHE_SIZE = 0
375 # Private class members and static file members will be hidden unless
375 # Private class members and static file members will be hidden unless
376 # the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
376 # the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
377
377
378 EXTRACT_ALL = NO
378 EXTRACT_ALL = YES
379
379
380 # If the EXTRACT_PRIVATE tag is set to YES all private members of a class
380 # If the EXTRACT_PRIVATE tag is set to YES all private members of a class
381 # will be included in the documentation.
381 # will be included in the documentation.
@@ -677,7 +677,7 WARN_LOGFILE =
677 # directories like "/usr/src/myproject". Separate the files or directories
677 # directories like "/usr/src/myproject". Separate the files or directories
678 # with spaces.
678 # with spaces.
679
679
680 INPUT = /opt/libuc2
680 INPUT = include
681
681
682 # This tag can be used to specify the character encoding of the source files
682 # This tag can be used to specify the character encoding of the source files
683 # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
683 # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
@@ -1621,7 +1621,7 INCLUDE_FILE_PATTERNS =
1621 # undefined via #undef or recursively expanded use the := operator
1621 # undefined via #undef or recursively expanded use the := operator
1622 # instead of the = operator.
1622 # instead of the = operator.
1623
1623
1624 PREDEFINED =
1624 PREDEFINED = DOXYGEN_SHOULD_SKIP_THIS
1625
1625
1626 # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
1626 # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
1627 # this tag can be used to specify a list of macro names that should be expanded.
1627 # this tag can be used to specify a list of macro names that should be expanded.
@@ -1687,7 +1687,7 PERL_PATH = /usr/bin/perl
1687 # this option also works with HAVE_DOT disabled, but it is recommended to
1687 # this option also works with HAVE_DOT disabled, but it is recommended to
1688 # install and use dot, since it yields more powerful graphs.
1688 # install and use dot, since it yields more powerful graphs.
1689
1689
1690 CLASS_DIAGRAMS = YES
1690 CLASS_DIAGRAMS = NO
1691
1691
1692 # You can define message sequence charts within doxygen comments using the \msc
1692 # You can define message sequence charts within doxygen comments using the \msc
1693 # command. Doxygen will then run the mscgen tool (see
1693 # command. Doxygen will then run the mscgen tool (see
@@ -1709,7 +1709,7 HIDE_UNDOC_RELATIONS = YES
1709 # toolkit from AT&T and Lucent Bell Labs. The other options in this section
1709 # toolkit from AT&T and Lucent Bell Labs. The other options in this section
1710 # have no effect if this option is set to NO (the default)
1710 # have no effect if this option is set to NO (the default)
1711
1711
1712 HAVE_DOT = NO
1712 HAVE_DOT = YES
1713
1713
1714 # The DOT_NUM_THREADS specifies the number of dot invocations doxygen is
1714 # The DOT_NUM_THREADS specifies the number of dot invocations doxygen is
1715 # allowed to run in parallel. When set to 0 (the default) doxygen will
1715 # allowed to run in parallel. When set to 0 (the default) doxygen will
@@ -1717,7 +1717,7 HAVE_DOT = NO
1717 # explicitly to a value larger than 0 to get control over the balance
1717 # explicitly to a value larger than 0 to get control over the balance
1718 # between CPU load and processing speed.
1718 # between CPU load and processing speed.
1719
1719
1720 DOT_NUM_THREADS = 0
1720 DOT_NUM_THREADS = 4
1721
1721
1722 # By default doxygen will use the Helvetica font for all dot files that
1722 # By default doxygen will use the Helvetica font for all dot files that
1723 # doxygen generates. When you want a differently looking font you can specify
1723 # doxygen generates. When you want a differently looking font you can specify
@@ -1798,7 +1798,7 INCLUDED_BY_GRAPH = YES
1798 # the time of a run. So in most cases it will be better to enable call graphs
1798 # the time of a run. So in most cases it will be better to enable call graphs
1799 # for selected functions only using the \callgraph command.
1799 # for selected functions only using the \callgraph command.
1800
1800
1801 CALL_GRAPH = NO
1801 CALL_GRAPH = YES
1802
1802
1803 # If the CALLER_GRAPH and HAVE_DOT tags are set to YES then
1803 # If the CALLER_GRAPH and HAVE_DOT tags are set to YES then
1804 # doxygen will generate a caller dependency graph for every global function
1804 # doxygen will generate a caller dependency graph for every global function
@@ -1806,7 +1806,7 CALL_GRAPH = NO
1806 # the time of a run. So in most cases it will be better to enable caller
1806 # the time of a run. So in most cases it will be better to enable caller
1807 # graphs for selected functions only using the \callergraph command.
1807 # graphs for selected functions only using the \callergraph command.
1808
1808
1809 CALLER_GRAPH = NO
1809 CALLER_GRAPH = YES
1810
1810
1811 # If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
1811 # If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
1812 # will generate a graphical hierarchy of all classes instead of a textual one.
1812 # will generate a graphical hierarchy of all classes instead of a textual one.
@@ -1835,7 +1835,7 DOT_IMAGE_FORMAT = png
1835 # need to set HTML_FILE_EXTENSION to xhtml in order to make the SVG files
1835 # need to set HTML_FILE_EXTENSION to xhtml in order to make the SVG files
1836 # visible. Older versions of IE do not have SVG support.
1836 # visible. Older versions of IE do not have SVG support.
1837
1837
1838 INTERACTIVE_SVG = NO
1838 INTERACTIVE_SVG = YES
1839
1839
1840 # The tag DOT_PATH can be used to specify the path where the dot tool can be
1840 # The tag DOT_PATH can be used to specify the path where the dot tool can be
1841 # found. If left blank, it is assumed the dot tool can be found in the path.
1841 # found. If left blank, it is assumed the dot tool can be found in the path.
@@ -22,7 +22,6
22
22
23 #include <SDL.h>
23 #include <SDL.h>
24 #include <ili9328.h>
24 #include <ili9328.h>
25 #include <stdint.h>
26
25
27 #define LCDILI9328 9328
26 #define LCDILI9328 9328
28
27
@@ -23,7 +23,6
23 #define GENERICLCD_CONTROLER_H
23 #define GENERICLCD_CONTROLER_H
24
24
25 #include <uhandle.h>
25 #include <uhandle.h>
26 #include <stdint.h>
27 #include <fonts.h>
26 #include <fonts.h>
28
27
29
28
@@ -22,10 +22,7
22 #ifndef ILI9328_H
22 #ifndef ILI9328_H
23 #define ILI9328_H
23 #define ILI9328_H
24
24
25 #include <uhandle.h>
26 #include <genericLCD_Controler.h>
25 #include <genericLCD_Controler.h>
27 #include <stdint.h>
28 #include <fonts.h>
29
26
30 extern int ili9328init(struct LCD_t* LCD);
27 extern int ili9328init(struct LCD_t* LCD);
31 extern void ili9328setFrame(LCD_t* LCD,uint16_t X,uint16_t Y,uint16_t W,uint16_t H);
28 extern void ili9328setFrame(LCD_t* LCD,uint16_t X,uint16_t Y,uint16_t W,uint16_t H);
@@ -22,10 +22,7
22 #ifndef SSD2119_H
22 #ifndef SSD2119_H
23 #define SSD2119_H
23 #define SSD2119_H
24
24
25 #include <uhandle.h>
26 #include <genericLCD_Controler.h>
25 #include <genericLCD_Controler.h>
27 #include <stdint.h>
28 #include <fonts.h>
29
26
30 extern int ssd2119init(struct LCD_t* LCD);
27 extern int ssd2119init(struct LCD_t* LCD);
31 extern void ssd2119setFrame(LCD_t* LCD,uint16_t X,uint16_t Y,uint16_t W,uint16_t H);
28 extern void ssd2119setFrame(LCD_t* LCD,uint16_t X,uint16_t Y,uint16_t W,uint16_t H);
@@ -21,11 +21,9
21 -------------------------------------------------------------------------------*/
21 -------------------------------------------------------------------------------*/
22 #ifndef TERMINAL_H
22 #ifndef TERMINAL_H
23 #define TERMINAL_H
23 #define TERMINAL_H
24 #include <stdint.h>
25 #include <widget.h>
24 #include <widget.h>
26 #include <streamdevices.h>
25 #include <streamdevices.h>
27 #include <genericLCD_Controler.h>
26 #include <genericLCD_Controler.h>
28 #include <fonts.h>
29
27
30 typedef struct terminal_t
28 typedef struct terminal_t
31 {
29 {
@@ -22,10 +22,7
22 #ifndef STMPE811_H
22 #ifndef STMPE811_H
23 #define STMPE811_H
23 #define STMPE811_H
24 #include <stdio.h>
24 #include <stdio.h>
25 #include <uhandle.h>
26 #include <genericTC_Controler.h>
25 #include <genericTC_Controler.h>
27 #include <stdint.h>
28 #include <fonts.h>
29 #include <spi.h>
26 #include <spi.h>
30
27
31 typedef struct ADS7843_t
28 typedef struct ADS7843_t
@@ -22,10 +22,7
22 #ifndef STMPE811_H
22 #ifndef STMPE811_H
23 #define STMPE811_H
23 #define STMPE811_H
24 #include <stdio.h>
24 #include <stdio.h>
25 #include <uhandle.h>
26 #include <genericTC_Controler.h>
25 #include <genericTC_Controler.h>
27 #include <stdint.h>
28 #include <fonts.h>
29 #include <i2c.h>
26 #include <i2c.h>
30
27
31 typedef struct STMPE811_t
28 typedef struct STMPE811_t
@@ -23,7 +23,6
23 #define GENERICTC_CONTROLER_H
23 #define GENERICTC_CONTROLER_H
24
24
25 #include <uhandle.h>
25 #include <uhandle.h>
26 #include <stdint.h>
27 #include <fonts.h>
26 #include <fonts.h>
28
27
29
28
@@ -22,7 +22,6
22 #ifndef STREAMDEVICES_H
22 #ifndef STREAMDEVICES_H
23 #define STREAMDEVICES_H
23 #define STREAMDEVICES_H
24 #include <uhandle.h>
24 #include <uhandle.h>
25 #include <stdint.h>
26
25
27 typedef struct streamdevice* streamdeviceptr;
26 typedef struct streamdevice* streamdeviceptr;
28 struct streamdevice_ops;
27 struct streamdevice_ops;
@@ -22,8 +22,6
22 #ifndef THREAD_H
22 #ifndef THREAD_H
23 #define THREAD_H
23 #define THREAD_H
24 #include <stdint.h>
24 #include <stdint.h>
25 #include <uhandle.h>
26 #include <streamdevices.h>
27
25
28 #ifdef __cplusplus
26 #ifdef __cplusplus
29 extern "C" {
27 extern "C" {
@@ -21,7 +21,7
21 -------------------------------------------------------------------------------*/
21 -------------------------------------------------------------------------------*/
22 #ifndef UHANDLE_H
22 #ifndef UHANDLE_H
23 #define UHANDLE_H
23 #define UHANDLE_H
24
24 #include <stdint.h>
25 typedef volatile void* UHANDLE;
25 typedef volatile void* UHANDLE;
26
26
27 #define uhandlevalide(HANDLE) ((HANDLE)!=0)
27 #define uhandlevalide(HANDLE) ((HANDLE)!=0)
@@ -18,10 +18,17 defineTest(copyFiles) {
18 }
18 }
19
19
20 INCLUDEPATH += $$[QT_INSTALL_HEADERS] \
20 INCLUDEPATH += $$[QT_INSTALL_HEADERS] \
21 $$[QT_INSTALL_HEADERS]/FS \
22 $$[QT_INSTALL_HEADERS]/EEPROMS \
23 $$[QT_INSTALL_HEADERS]/AUDIO \
24 $$[QT_INSTALL_HEADERS]/POWER \
25 $$[QT_INSTALL_HEADERS]/PERIPHERALS \
26 $$[QT_INSTALL_HEADERS]/FLASH \
27 $$[QT_INSTALL_HEADERS]/ADC \
21 $$[QT_INSTALL_HEADERS]/GRAPHIC/CONTROLERS \
28 $$[QT_INSTALL_HEADERS]/GRAPHIC/CONTROLERS \
22 $$[QT_INSTALL_HEADERS]/GRAPHIC/TC_CONTROLERS \
29 $$[QT_INSTALL_HEADERS]/GRAPHIC/TC_CONTROLERS \
23 $$[QT_INSTALL_HEADERS]/GRAPHIC/GUI/FONTS \
30 $$[QT_INSTALL_HEADERS]/GRAPHIC/GUI/FONTS \
24 $$[QT_INSTALL_HEADERS]/GRAPHIC/GUI/Widgets
31 $$[QT_INSTALL_HEADERS]/GRAPHIC/GUI/Widgets
25
32
26 #
33 #
27 # Microcontroler switch
34 # Microcontroler switch
@@ -6,4 +6,7 SOURCES += VS10XX.c
6
6
7 UCMODEL=simulator
7 UCMODEL=simulator
8
8
9 HEADERS += \
10 ../../../../include/AUDIO/VS10XX.h
9
11
12
@@ -7,3 +7,7 SOURCES += VS10XX.c
7
7
8 UCMODEL=stm32f4
8 UCMODEL=stm32f4
9
9
10 HEADERS += \
11 ../../../../include/AUDIO/VS10XX.h
12
13
@@ -6,3 +6,6 SOURCES += ina226.c
6
6
7 UCMODEL=simulator
7 UCMODEL=simulator
8
8
9 HEADERS += \
10 ../../../../include/POWER/ina226.h
11
@@ -6,3 +6,6 SOURCES += ina226.c
6
6
7 UCMODEL=stm32f4
7 UCMODEL=stm32f4
8
8
9 HEADERS += \
10 ../../../../include/POWER/ina226.h
11
@@ -22,7 +22,7
22
22
23 #include <SDL.h>
23 #include <SDL.h>
24 #include <malloc.h>
24 #include <malloc.h>
25 #include "SDLCD.h"
25 #include <SDLCD.h>
26
26
27 SDL_Surface *screen;
27 SDL_Surface *screen;
28 SDL_Overlay *bmp;
28 SDL_Overlay *bmp;
@@ -29,7 +29,7 void UsageFault_Handler(void)
29 void SVC_Handler(void)
29 void SVC_Handler(void)
30 {
30 {
31 // __set_CONTROL(2);
31 // __set_CONTROL(2);
32 // printf("SVC_Handler\n");
32 printf("SVC_Handler\n");
33 }
33 }
34
34
35 void DebugMon_Handler(void)
35 void DebugMon_Handler(void)
@@ -5,6 +5,9 SOURCES += gpio.c
5
5
6 UCMODEL=stm32f4
6 UCMODEL=stm32f4
7
7
8 HEADERS += \
9 ../../../include/PERIPHERALS/gpio.h
8
10
9
11
10
12
13
@@ -6,5 +6,8 SOURCES += i2c.c
6
6
7 UCMODEL=stm32f4
7 UCMODEL=stm32f4
8
8
9 HEADERS += \
10 ../../../include/PERIPHERALS/i2c.h
9
11
10
12
13
@@ -4,3 +4,6 CONFIG += libuc2lib
4 SOURCES += sdcard-sdio.c
4 SOURCES += sdcard-sdio.c
5
5
6 UCMODEL=stm32f4
6 UCMODEL=stm32f4
7
8 HEADERS += \
9 ../../../include/FLASH/sdcard-sdio.h
@@ -6,3 +6,6 SOURCES += spi.c
6
6
7 UCMODEL=stm32f4
7 UCMODEL=stm32f4
8
8
9 HEADERS += \
10 ../../../include/PERIPHERALS/spi.h
11
@@ -4,3 +4,7 CONFIG += libuc2lib
4 SOURCES += uart.c
4 SOURCES += uart.c
5
5
6 UCMODEL=stm32f4
6 UCMODEL=stm32f4
7
8 HEADERS += \
9 ../../../include/PERIPHERALS/uart.h
10
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (557 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now