@@ -66,6 +66,42 @@ static inline uint32_t mapResolution(uint32_t value,
6666}
6767
6868PinStatus digitalReadClearCore (pin_size_t conNum) {
69+ // check if trying to read a motor input
70+ if (conNum > CLEARCORE_PIN_MAX && conNum <= INBM3) {
71+ int motorPin = -1 ;
72+ switch (conNum) {
73+ case INAM0:
74+ case INBM0:
75+ motorPin = M0;
76+ break ;
77+ case INAM1:
78+ case INBM1:
79+ motorPin = M1;
80+ break ;
81+ case INAM2:
82+ case INBM2:
83+ motorPin = M2;
84+ break ;
85+ case INAM3:
86+ case INBM3:
87+ motorPin = M3;
88+ break ;
89+ }
90+
91+ // Get a reference to the appropriate motor
92+ ClearCore::MotorDriver *motor =
93+ static_cast <ClearCore::MotorDriver*>(
94+ ClearCore::SysMgr.ConnectorByIndex (
95+ static_cast <ClearCorePins>(motorPin)));
96+
97+ if (conNum > CLEARCORE_PIN_MAX && conNum < INBM0) {
98+ return motor->MotorInAState () ? LOW : HIGH;
99+ }
100+ else {
101+ return motor->MotorInBState () ? LOW : HIGH;
102+ }
103+ }
104+
69105 // Get a reference to the appropriate connector
70106 ClearCore::Connector *connector =
71107 ClearCore::SysMgr.ConnectorByIndex (
@@ -84,20 +120,57 @@ PinStatus digitalReadClearCore(pin_size_t conNum) {
84120}
85121
86122void digitalWriteClearCore (pin_size_t conNum, PinStatus ulVal) {
87- // Get a reference to the appropriate connector
88- ClearCore::Connector *connector =
89- ClearCore::SysMgr.ConnectorByIndex (
90- static_cast <ClearCorePins>(conNum));
91-
92- // If connector cannot be written, just return
93- if (!connector || !connector->IsWritable ()) {
94- return ;
95- }
123+ // check if trying to write to a motor input
124+ if (conNum > CLEARCORE_PIN_MAX && conNum <= INBM3) {
125+ int motorPin = -1 ;
126+ switch (conNum) {
127+ case INAM0:
128+ case INBM0:
129+ motorPin = M0;
130+ break ;
131+ case INAM1:
132+ case INBM1:
133+ motorPin = M1;
134+ break ;
135+ case INAM2:
136+ case INBM2:
137+ motorPin = M2;
138+ break ;
139+ case INAM3:
140+ case INBM3:
141+ motorPin = M3;
142+ break ;
143+ }
144+
145+ // Get a reference to the appropriate motor
146+ ClearCore::MotorDriver *motor =
147+ static_cast <ClearCore::MotorDriver*>(
148+ ClearCore::SysMgr.ConnectorByIndex (
149+ static_cast <ClearCorePins>(motorPin)));
150+
151+ if (conNum > CLEARCORE_PIN_MAX && conNum < INBM0) {
152+ motor->MotorInAState (ulVal);
153+ }
154+ else {
155+ motor->MotorInBState (ulVal);
156+ }
157+ }
158+ else {
159+ // Get a reference to the appropriate connector
160+ ClearCore::Connector *connector =
161+ ClearCore::SysMgr.ConnectorByIndex (
162+ static_cast <ClearCorePins>(conNum));
163+
164+ // If connector cannot be written, just return
165+ if (!connector || !connector->IsWritable ()) {
166+ return ;
167+ }
96168
97- connector->Mode (ClearCore::Connector::OUTPUT_DIGITAL);
98- if (connector->Mode () == ClearCore::Connector::OUTPUT_DIGITAL) {
99- connector->State (ulVal);
100- }
169+ connector->Mode (ClearCore::Connector::OUTPUT_DIGITAL);
170+ if (connector->Mode () == ClearCore::Connector::OUTPUT_DIGITAL) {
171+ connector->State (ulVal);
172+ }
173+ }
101174}
102175
103176/* *
0 commit comments