Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
仰若水
YADS1299
Commits
08c52bfd
Commit
08c52bfd
authored
4 years ago
by
仰若水
Browse files
Options
Download
Email Patches
Plain Diff
ADS1299 rename to YADS1299. Added config API.
parent
d60d7ac1
master
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
y_ads1299.hpp
+92
-70
y_ads1299.hpp
y_ads1299_esp32.hpp
+1
-1
y_ads1299_esp32.hpp
y_ads1299_stm32.cpp
+2
-2
y_ads1299_stm32.cpp
y_ads1299_stm32.hpp
+1
-1
y_ads1299_stm32.hpp
with
96 additions
and
74 deletions
+96
-74
y_ads1299.hpp
View file @
08c52bfd
...
...
@@ -15,11 +15,50 @@
#include <cstdint>
namespace
ADS1299
{
namespace
Y
ADS1299
{
enum
Status
{
OK
,
Error
,
Busy
,
Timeout
};
enum
SampleRate
{
// REG_CONFIG1_OUTPUT_DATA_RATE
SampleRate_16000
,
SampleRate_8000
,
SampleRate_4000
,
SampleRate_2000
,
SampleRate_1000
,
SampleRate_500
,
SampleRate_250
,
SampleRate_Max
};
static
constexpr
uint8_t
REG_REG_CH_N_SET_GAIN
(
uint8_t
n
)
{
return
n
<<
4
;
}
enum
Gain
{
// REG_REG_CH_N_SET_GAIN
Gain_1
=
REG_REG_CH_N_SET_GAIN
(
0
),
Gain_2
=
REG_REG_CH_N_SET_GAIN
(
1
),
Gain_4
=
REG_REG_CH_N_SET_GAIN
(
2
),
Gain_6
=
REG_REG_CH_N_SET_GAIN
(
3
),
Gain_8
=
REG_REG_CH_N_SET_GAIN
(
4
),
Gain_12
=
REG_REG_CH_N_SET_GAIN
(
5
),
Gain_24
=
REG_REG_CH_N_SET_GAIN
(
6
),
};
enum
Mux
{
// REG_REG_CH_N_SET_NUX
NormalElectrodeInput
,
InputShorted
,
BiasMeasure
,
MVDD
,
Temperature
,
Test
,
BIAS_DRP
,
BIAS_DRN
,
};
static
inline
void
delay
(
uint32_t
ms
);
static
inline
Status
spiChangeToHighSpeed
();
static
inline
Status
spiTransmit
(
uint8_t
*
pData
,
uint16_t
size
);
...
...
@@ -34,11 +73,8 @@ static inline Status spiTransmitReceive(uint8_t *pData, uint16_t size);
}
template
<
uint8_t
Channels
>
class
YADS1299
{
class
YADS1299
Instance
{
public:
static
constexpr
uint8_t
REG_REG_CH_N_SET_GAIN
(
uint8_t
n
)
{
return
n
<<
4
;
}
static
constexpr
uint8_t
channels
()
{
return
Channels
;
...
...
@@ -91,14 +127,6 @@ public:
REG_CONFIG1_CLK_CONNECTION_OUTPUT_DISABLED
=
0
<<
5
,
REG_CONFIG1_CLK_CONNECTION_OUTPUT_ENABLED
=
1
<<
5
,
REG_CONFIG1_OUTPUT_DATA_RATE_16000
=
0
,
REG_CONFIG1_OUTPUT_DATA_RATE_8000
,
REG_CONFIG1_OUTPUT_DATA_RATE_4000
,
REG_CONFIG1_OUTPUT_DATA_RATE_2000
,
REG_CONFIG1_OUTPUT_DATA_RATE_1000
,
REG_CONFIG1_OUTPUT_DATA_RATE_500
,
REG_CONFIG1_OUTPUT_DATA_RATE_250
,
REG_CONFIG2_BASE
=
0xC0
,
// 11= 0x= 0xxx
REG_CONFIG2_TEST_SOURCEE_EXTERNALLY
=
0
<<
4
,
...
...
@@ -134,26 +162,9 @@ public:
REG_REG_CH_N_SET_PD_NORMOL
=
0
<<
7
,
REG_REG_CH_N_SET_PD_DOWN
=
1
<<
7
,
REG_REG_CH_N_SET_GAIN_1
=
REG_REG_CH_N_SET_GAIN
(
0
),
REG_REG_CH_N_SET_GAIN_2
=
REG_REG_CH_N_SET_GAIN
(
1
),
REG_REG_CH_N_SET_GAIN_4
=
REG_REG_CH_N_SET_GAIN
(
2
),
REG_REG_CH_N_SET_GAIN_6
=
REG_REG_CH_N_SET_GAIN
(
3
),
REG_REG_CH_N_SET_GAIN_8
=
REG_REG_CH_N_SET_GAIN
(
4
),
REG_REG_CH_N_SET_GAIN_12
=
REG_REG_CH_N_SET_GAIN
(
5
),
REG_REG_CH_N_SET_GAIN_24
=
REG_REG_CH_N_SET_GAIN
(
6
),
REG_REG_CH_N_SET_SRB2_OPEN
=
0
<<
3
,
REG_REG_CH_N_SET_SRB2_CLOSED
=
1
<<
3
,
REG_REG_CH_N_SET_NUX_NORMAL_ELECTRODE_INPUT
=
0
,
REG_REG_CH_N_SET_NUX_INPUT_SHORTED
,
REG_REG_CH_N_SET_NUX_BIAS_MEAS
,
REG_REG_CH_N_SET_NUX_MVDD
,
REG_REG_CH_N_SET_NUX_TEMPERATURE
,
REG_REG_CH_N_SET_NUX_TEST
,
REG_REG_CH_N_SET_NUX_BIAS_DRP
,
REG_REG_CH_N_SET_NUX_BIAS_DRN
,
REG_MISC1_SRB1_OPEN
=
0
<<
5
,
REG_MISC1_SRB1_CLOSED
=
1
<<
5
,
...
...
@@ -161,7 +172,7 @@ public:
CONVERSION_MODE_SINGLE_SHOT
=
1
<<
3
};
YADS1299
()
{
YADS1299
Instance
()
{
}
struct
IDsData
{
...
...
@@ -169,22 +180,22 @@ public:
uint8_t
ids
[
devices
()];
};
ADS1299
::
Status
init
()
{
uint8_t
cmdReg
[
10
];
Y
ADS1299
::
Status
init
()
{
uint8_t
cmdReg
[
9
];
// Reset the device.
cmdReg
[
0
]
=
CMD_RESET
;
ADS1299
::
Status
status
;
if
((
status
=
ADS1299
::
spiTransmit
(
cmdReg
,
1
))
!=
ADS1299
::
OK
)
Y
ADS1299
::
Status
status
;
if
((
status
=
Y
ADS1299
::
spiTransmit
(
cmdReg
,
1
))
!=
Y
ADS1299
::
OK
)
return
status
;
ADS1299
::
delay
(
100
);
Y
ADS1299
::
delay
(
100
);
// cmd = CMD_WEAKUP;
// if ((status = SPI_Transmit(&cmd, 1)) != Y_LOG_OK) return status;
// Delay_ms(100);
if
((
status
=
stopReadDataContinuous
())
!=
ADS1299
::
OK
)
if
((
status
=
stopReadDataContinuous
())
!=
Y
ADS1299
::
OK
)
return
status
;
ADS1299
::
delay
(
100
);
Y
ADS1299
::
delay
(
100
);
if
(
Channels
>
8
)
{
// Enable first device to supply time signal when use the daisy mode.
...
...
@@ -199,9 +210,9 @@ public:
cmdReg
[
6
]
=
REG_CONFIG3_BASE
;
cmdReg
[
7
]
=
REG_CONFIG3_BASE
;
cmdReg
[
8
]
=
REG_CONFIG3_BASE
;
if
((
status
=
ADS1299
::
spiTransmit
(
cmdReg
,
9
))
!=
ADS1299
::
OK
)
if
((
status
=
Y
ADS1299
::
spiTransmit
(
cmdReg
,
9
))
!=
Y
ADS1299
::
OK
)
return
status
;
ADS1299
::
delay
(
100
);
Y
ADS1299
::
delay
(
100
);
}
// Basic config.
...
...
@@ -209,7 +220,7 @@ public:
cmdReg
[
1
]
=
2
;
cmdReg
[
2
]
=
REG_CONFIG1_BASE
|
REG_CONFIG1_MULTIDEVICE_DAISY_CHAIN_MODE
|
REG_CONFIG1_CLK_CONNECTION_OUTPUT_ENABLED
|
REG_CONFIG1_OUTPUT_DATA_RATE
_500
;
|
YADS1299
::
SampleRate
_500
;
cmdReg
[
3
]
=
REG_CONFIG2_BASE
|
REG_CONFIG2_TEST_SOURCEE_INTERNALLY
|
REG_CONFIG2_TEST_SIGNAL_AMPLITUDE_2X
|
REG_CONFIG2_TEST_SIGNAL_FREQUENCY_FCLK_DIV_2_21
;
...
...
@@ -220,20 +231,11 @@ public:
|
REG_CONFIG3_PD_BIAS_ENABLE
|
REG_CONFIG3_BIAS_LOFF_SENS_DISABLE
|
REG_CONFIG3_BIAS_STAT_DISABLE
;
if
((
status
=
ADS1299
::
spiTransmit
(
cmdReg
,
5
))
!=
ADS1299
::
OK
)
if
((
status
=
Y
ADS1299
::
spiTransmit
(
cmdReg
,
5
))
!=
Y
ADS1299
::
OK
)
return
status
;
// Config channels
cmdReg
[
0
]
=
CMD_WREG
|
REG_CH1SET
;
cmdReg
[
1
]
=
7
;
// channelsReg[2] = REG_REG_CH_N_SET_PD_NORMOL | REG_REG_CH_N_SET_GAIN_12 | REG_REG_CH_N_SET_SRB2_OPEN | REG_REG_CH_N_SET_NUX_NORMAL_ELECTRODE_INPUT;
// channelsReg[3] = REG_REG_CH_N_SET_PD_NORMOL | REG_REG_CH_N_SET_GAIN_12 | REG_REG_CH_N_SET_SRB2_OPEN | REG_REG_CH_N_SET_NUX_NORMAL_ELECTRODE_INPUT;
// channelsReg[4] = REG_REG_CH_N_SET_PD_NORMOL | REG_REG_CH_N_SET_GAIN_12 | REG_REG_CH_N_SET_SRB2_OPEN | REG_REG_CH_N_SET_NUX_BIAS_MEAS;
for
(
uint8_t
i
=
2
;
i
<
10
;
i
++
)
{
cmdReg
[
i
]
=
REG_REG_CH_N_SET_PD_NORMOL
|
REG_REG_CH_N_SET_GAIN_12
|
REG_REG_CH_N_SET_SRB2_OPEN
|
REG_REG_CH_N_SET_NUX_TEST
;
}
if
((
status
=
ADS1299
::
spiTransmit
(
cmdReg
,
10
))
!=
ADS1299
::
OK
)
if
((
status
=
setGainAndMux
(
YADS1299
::
Gain_12
,
YADS1299
::
NormalElectrodeInput
))
!=
YADS1299
::
OK
)
return
status
;
// Config basis
...
...
@@ -241,22 +243,22 @@ public:
cmdReg
[
1
]
=
1
;
cmdReg
[
2
]
=
3
;
cmdReg
[
3
]
=
3
;
if
((
status
=
ADS1299
::
spiTransmit
(
cmdReg
,
4
))
!=
ADS1299
::
OK
)
if
((
status
=
Y
ADS1299
::
spiTransmit
(
cmdReg
,
4
))
!=
Y
ADS1299
::
OK
)
return
status
;
// Config MISC
cmdReg
[
0
]
=
CMD_WREG
|
REG_MISC1
;
cmdReg
[
1
]
=
0
;
cmdReg
[
2
]
=
REG_MISC1_SRB1_CLOSED
;
if
((
status
=
ADS1299
::
spiTransmit
(
cmdReg
,
3
))
!=
ADS1299
::
OK
)
if
((
status
=
Y
ADS1299
::
spiTransmit
(
cmdReg
,
3
))
!=
Y
ADS1299
::
OK
)
return
status
;
ADS1299
::
delay
(
10
);
Y
ADS1299
::
delay
(
10
);
return
status
;
}
void
weakUp
()
{
sendCMD
(
WeakUp
);
ADS1299
::
delay
(
1
);
Y
ADS1299
::
delay
(
1
);
}
void
standby
()
{
...
...
@@ -271,14 +273,14 @@ public:
sendCMD
(
CMD_STOP
);
}
ADS1299
::
Status
startReadDataContinuous
()
{
Y
ADS1299
::
Status
startReadDataContinuous
()
{
auto
res
=
sendCMD
(
CMD_RDATAC
);
if
(
res
!=
ADS1299
::
OK
)
if
(
res
!=
Y
ADS1299
::
OK
)
return
res
;
return
ADS1299
::
spiChangeToHighSpeed
();
return
Y
ADS1299
::
spiChangeToHighSpeed
();
}
ADS1299
::
Status
stopReadDataContinuous
()
{
Y
ADS1299
::
Status
stopReadDataContinuous
()
{
return
sendCMD
(
CMD_SDATAC
);
}
...
...
@@ -286,41 +288,61 @@ public:
// uint8_t cmd[3] = {CMD_WREG | REG_CONFIG4, 0, mode};
// SPI_Transmit(cmd, 3);
uint8_t
cmdd
[
3
]
=
{
CMD_WREG
|
REG_CONFIG3
,
0
,
0xE0
};
ADS1299
::
spiTransmit
(
cmdd
,
3
);
Y
ADS1299
::
spiTransmit
(
cmdd
,
3
);
uint8_t
cmd2
[
3
]
=
{
CMD_WREG
|
REG_CONFIG1
,
0
,
0x96
};
ADS1299
::
spiTransmit
(
cmd2
,
3
);
Y
ADS1299
::
spiTransmit
(
cmd2
,
3
);
uint8_t
cmd3
[
3
]
=
{
CMD_WREG
|
REG_CONFIG2
,
0
,
0xC0
};
ADS1299
::
spiTransmit
(
cmd3
,
3
);
Y
ADS1299
::
spiTransmit
(
cmd3
,
3
);
}
uint8_t
id
()
{
uint8_t
cmd
[
3
]
=
{
CMD_RREG
|
REG_ID
};
ADS1299
::
spiTransmitReceive
(
cmd
,
3
);
Y
ADS1299
::
spiTransmitReceive
(
cmd
,
3
);
return
cmd
[
2
];
}
void
ids
(
IDsData
*
ids
)
{
ids
->
__cmd
=
CMD_RREG
|
REG_ID
;
ADS1299
::
spiTransmitReceive
((
uint8_t
*
)
ids
,
sizeof
(
IDsData
));
Y
ADS1299
::
spiTransmitReceive
((
uint8_t
*
)
ids
,
sizeof
(
IDsData
));
}
void
readData
()
{
uint8_t
data
[
28
]
=
{
CMD_RDATAC
};
ADS1299
::
spiTransmitReceive
(
data
,
28
);
Y
ADS1299
::
spiTransmitReceive
(
data
,
28
);
}
void
readDataContinuous
(
uint8_t
*
data
)
{
ADS1299
::
spiReceive
(
data
,
receiveSize
());
Y
ADS1299
::
spiReceive
(
data
,
receiveSize
());
}
void
readDataContinuousAsync
(
uint8_t
*
data
)
{
ADS1299
::
spiReceiveAsync
(
data
,
receiveSize
());
YADS1299
::
spiReceiveAsync
(
data
,
receiveSize
());
}
YADS1299
::
Status
setSampleRate
(
YADS1299
::
SampleRate
sampleRate
)
{
uint8_t
cmdReg
[
3
];
cmdReg
[
0
]
=
CMD_WREG
|
REG_CONFIG1
;
cmdReg
[
1
]
=
0
;
cmdReg
[
2
]
=
REG_CONFIG1_BASE
|
REG_CONFIG1_MULTIDEVICE_DAISY_CHAIN_MODE
|
REG_CONFIG1_CLK_CONNECTION_OUTPUT_ENABLED
|
sampleRate
;
return
YADS1299
::
spiTransmit
(
cmdReg
,
sizeof
(
cmdReg
));
}
YADS1299
::
Status
setGainAndMux
(
YADS1299
::
Gain
gain
,
YADS1299
::
Mux
mux
)
{
uint8_t
cmdReg
[
10
];
cmdReg
[
0
]
=
CMD_WREG
|
REG_CH1SET
;
cmdReg
[
1
]
=
7
;
for
(
uint8_t
i
=
2
;
i
<
10
;
i
++
)
{
cmdReg
[
i
]
=
REG_REG_CH_N_SET_PD_NORMOL
|
gain
|
REG_REG_CH_N_SET_SRB2_OPEN
|
mux
;
}
return
YADS1299
::
spiTransmit
(
cmdReg
,
sizeof
(
cmdReg
));
}
private:
ADS1299
::
Status
sendCMD
(
uint8_t
cmd
)
{
return
ADS1299
::
spiTransmit
(
&
cmd
,
1
);
Y
ADS1299
::
Status
sendCMD
(
uint8_t
cmd
)
{
return
Y
ADS1299
::
spiTransmit
(
&
cmd
,
1
);
}
//uint8_t channels;
...
...
This diff is collapsed.
Click to expand it.
y_ads1299_esp32.hpp
View file @
08c52bfd
...
...
@@ -19,7 +19,7 @@ extern spi_device_handle_t spiADS1299;
// https://docs.espressif.com/projects/esp-idf/zh_CN/latest/esp32/api-reference/peripherals/spi_master.html#spi-known-issues
extern
uint8_t
*
spiEmptyData
;
namespace
ADS1299
{
namespace
Y
ADS1299
{
static
inline
void
delay
(
uint32_t
ms
)
{
vTaskDelay
(
pdMS_TO_TICKS
(
ms
));
}
...
...
This diff is collapsed.
Click to expand it.
y_ads1299_stm32.cpp
View file @
08c52bfd
...
...
@@ -10,12 +10,12 @@
/* 通信接口 */
namespace
ADS1299
{
namespace
Y
ADS1299
{
#ifdef STM32F0xx_HAL_SPI_H
__ALIGNED
(
2
)
#endif
const
uint8_t
emptyData
[
YADS1299
<
ADS1299MaxChannels
>::
receiveSize
()]
=
{
0
};
const
uint8_t
emptyData
[
YADS1299
Instance
<
ADS1299MaxChannels
>::
receiveSize
()]
=
{
0
};
void
ADS1299_ReadDataContinuousCallback
();
...
...
This diff is collapsed.
Click to expand it.
y_ads1299_stm32.hpp
View file @
08c52bfd
...
...
@@ -20,7 +20,7 @@
extern
SPI_HandleTypeDef
hspi1
;
namespace
ADS1299
{
namespace
Y
ADS1299
{
extern
const
uint8_t
emptyData
[];
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help