Skip to content

Commit 7c9f845

Browse files
committed
passthrough - 2.2 mA
1 parent 28cfbbd commit 7c9f845

File tree

1 file changed

+72
-0
lines changed
  • Projects/Multi/Applications/LoRa/AT_Slave/src

1 file changed

+72
-0
lines changed

Projects/Multi/Applications/LoRa/AT_Slave/src/main.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,71 @@ void HW_Main_Init()
170170
HW_GpioInit();
171171
}
172172

173+
static bool goDumb() {
174+
// Setup GPIOPB12 as input
175+
GPIO_InitTypeDef initStruct={0};
176+
initStruct.Mode = GPIO_MODE_INPUT;
177+
initStruct.Pull = GPIO_PULLUP;
178+
initStruct.Speed = GPIO_SPEED_HIGH;
179+
180+
HW_GPIO_Init( GPIOB, GPIO_PIN_12, &initStruct );
181+
182+
return HW_GPIO_Read(GPIOB, GPIO_PIN_12) == 0;
183+
}
184+
185+
void setupPassthrough() {
186+
// input pins
187+
GPIO_InitTypeDef initStruct={0};
188+
initStruct.Mode = GPIO_MODE_INPUT;
189+
initStruct.Pull = GPIO_NOPULL;
190+
initStruct.Speed = GPIO_SPEED_HIGH;
191+
192+
HW_GPIO_Init( GPIOB, GPIO_PIN_13, &initStruct );
193+
HW_GPIO_Init( GPIOA, GPIO_PIN_3, &initStruct );
194+
HW_GPIO_Init( GPIOA, GPIO_PIN_6, &initStruct );
195+
HW_GPIO_Init( GPIOB, GPIO_PIN_4, &initStruct );
196+
197+
// output pins
198+
initStruct.Mode = GPIO_MODE_OUTPUT_PP;
199+
initStruct.Pull = GPIO_NOPULL;
200+
201+
HW_GPIO_Init( GPIOB, GPIO_PIN_3, &initStruct );
202+
HW_GPIO_Init( GPIOA, GPIO_PIN_7, &initStruct );
203+
HW_GPIO_Init( GPIOA, GPIO_PIN_2, &initStruct );
204+
#ifdef USE_DIO0_IRQ
205+
HW_GPIO_Init( GPIOB, GPIO_PIN_12, &initStruct );
206+
#endif
207+
HW_GPIO_Init( GPIOB, GPIO_PIN_15, &initStruct );
208+
209+
// reset and SS pins
210+
SX1276Reset();
211+
HW_GPIO_Init( RADIO_NSS_PORT, RADIO_NSS_PIN, &initStruct );
212+
#ifdef USE_DIO0_IRQ
213+
HW_GPIO_Write( RADIO_NSS_PORT, RADIO_NSS_PIN, 0 );
214+
#endif
215+
}
216+
217+
static inline void runPassthrough() {
218+
// PB13 -> PB3
219+
// PA3 -> PA7
220+
// PA6 -> PA2
221+
// PB4 -> PB12
222+
223+
#define PORTA_OUT_MASK ((1 << 2) | (1 << 7) | (1 << 15))
224+
225+
uint32_t InPortA = READ_REG(GPIOA->IDR);
226+
uint32_t InPortB = READ_REG(GPIOB->IDR);
227+
228+
uint32_t OutPortB = (((InPortB & GPIO_PIN_13) >> 10));
229+
uint32_t OutPortA = ((InPortA & GPIO_PIN_3) << 4) | ((InPortA & GPIO_PIN_6) >> 4) | ((InPortB & GPIO_PIN_12) << 3);
230+
231+
WRITE_REG(GPIOA->BSRR, ((OutPortA & PORTA_OUT_MASK) | ((~OutPortA & PORTA_OUT_MASK) << 16)));
232+
WRITE_REG(GPIOB->BSRR, ((OutPortB & (1 << 3)) | (((~OutPortB & (1 << 3)) << 16))));
233+
return;
234+
}
235+
236+
237+
173238
LoRaMacRegion_t globalRegion = LORAMAC_REGION_EU868;
174239

175240
int main(void)
@@ -180,6 +245,13 @@ int main(void)
180245
/* Configure the system clock*/
181246
SystemClock_Config();
182247

248+
/* Read SS input (GPIOPB12); if low, enter dumb mode */
249+
if (goDumb()) {
250+
setupPassthrough();
251+
while (1) {
252+
runPassthrough();
253+
}
254+
}
183255
/* Configure the hardware*/
184256
HW_Init();
185257

0 commit comments

Comments
 (0)