@@ -165,6 +165,10 @@ IServiceLocator *locator;
165165 FsSpiffs spiffs1 ;
166166#endif
167167
168+ #if defined(CONFIG_PLUMPOT_CELLULAR_UXB_VOLTAGE )
169+ #include "services/adc-sensor/adc-sensor.h"
170+ AdcSensor sensor_uxb_voltage ;
171+ #endif
168172
169173SystemClock system_clock ;
170174Stm32Rtc rtc ;
@@ -302,20 +306,25 @@ int32_t port_init(void) {
302306 "profiler1"
303307 );
304308
309+ /* Configure and release all CS lines. */
310+ gpio_set (GPIOB , GPIO2 | GPIO12 );
311+ gpio_mode_setup (GPIOB , GPIO_MODE_OUTPUT , GPIO_PUPD_NONE , GPIO2 | GPIO12 );
312+ gpio_set_output_options (GPIOB , GPIO_OTYPE_PP , GPIO_OSPEED_2MHZ , GPIO2 | GPIO12 );
313+
305314 /* Configure GPIO for radio & flash SPI bus (SPI2), enable SPI2 clock and
306315 * run spibus driver using libopencm3 to access it. */
307316 gpio_mode_setup (GPIOB , GPIO_MODE_AF , GPIO_PUPD_NONE , GPIO13 | GPIO14 | GPIO15 );
308- gpio_set_output_options (GPIOB , GPIO_OTYPE_PP , GPIO_OSPEED_50MHZ , GPIO13 | GPIO14 | GPIO15 );
317+ gpio_set_output_options (GPIOB , GPIO_OTYPE_PP , GPIO_OSPEED_2MHZ , GPIO13 | GPIO14 | GPIO15 );
309318 gpio_set_af (GPIOB , GPIO_AF5 , GPIO13 | GPIO14 | GPIO15 );
310319 rcc_periph_clock_enable (RCC_SPI2 );
311- rcc_periph_reset_pulse (RST_SPI2 );
320+ // rcc_periph_reset_pulse(RST_SPI2);
312321 module_spibus_locm3_init (& spi2 , "spi2" , SPI2 );
313322 hal_interface_set_name (& (spi2 .iface .descriptor ), "spi2" );
314323
315324 /* Initialize SPI device on the SPI2 bus. */
316325 gpio_set (GPIOB , GPIO12 );
317326 gpio_mode_setup (GPIOB , GPIO_MODE_OUTPUT , GPIO_PUPD_NONE , GPIO12 );
318- gpio_set_output_options (GPIOB , GPIO_OTYPE_PP , GPIO_OSPEED_50MHZ , GPIO12 );
327+ gpio_set_output_options (GPIOB , GPIO_OTYPE_PP , GPIO_OSPEED_2MHZ , GPIO12 );
319328 module_spidev_locm3_init (& spi2_flash1 , "spi2_flash1" , & (spi2 .iface ), GPIOB , GPIO12 );
320329 hal_interface_set_name (& (spi2_flash1 .iface .descriptor ), "spi2_flash1" );
321330
@@ -327,31 +336,49 @@ int32_t port_init(void) {
327336 & (spi_flash_interface (& spi_flash1 )-> interface ),
328337 "spi-flash1"
329338 );
339+ #if defined(CONFIG_SERVICE_FS_SPIFFS )
340+ fs_spiffs_init (& spiffs1 );
341+ // fs_spiffs_format(&spiffs1, spi_flash_interface(&spi_flash1));
342+ if (fs_spiffs_mount (& spiffs1 , spi_flash_interface (& spi_flash1 )) == FS_SPIFFS_RET_OK ) {
343+ iservicelocator_add (
344+ locator ,
345+ ISERVICELOCATOR_TYPE_FS ,
346+ & (fs_spiffs_interface (& spiffs1 )-> interface ),
347+ "system"
348+ );
349+ }
350+ #endif
330351 }
331-
332- #if defined(CONFIG_SERVICE_FS_SPIFFS )
333- fs_spiffs_init (& spiffs1 );
334- // fs_spiffs_format(&spiffs1, spi_flash_interface(&spi_flash1));
335- if (fs_spiffs_mount (& spiffs1 , spi_flash_interface (& spi_flash1 )) == FS_SPIFFS_RET_OK ) {
336- iservicelocator_add (
337- locator ,
338- ISERVICELOCATOR_TYPE_FS ,
339- & (fs_spiffs_interface (& spiffs1 )-> interface ),
340- "system"
341- );
342- }
343- #endif
344352 #endif
345353
346354 /* ADC initialization (power metering, prng seeding) */
347355 #if defined(CONFIG_SERVICE_STM32_ADC )
348356 adc_stm32_locm3_init (& adc1 , ADC1 );
349357 #endif
350358
351- /* Battery power device (using ADC). */
352- /** @todo resolve incompatible interfaces */
353- // module_power_adc_init(&vin1, "vin1", &(adc1.iface), &vin1_config);
354- // module_power_adc_init(&ubx_voltage, "ubx1", &(adc1.iface), &ubx_voltage_config);
359+ #if defined(CONFIG_PLUMPOT_CELLULAR_UXB_VOLTAGE )
360+ gpio_mode_setup (GPIOA , GPIO_MODE_ANALOG , GPIO_PUPD_NONE , GPIO6 );
361+
362+ adc_sensor_init (
363+ & sensor_uxb_voltage ,
364+ & adc1 .iface ,
365+ 6 ,
366+ & (ISensorInfo ) {
367+ .quantity_name = "Voltage" ,
368+ .quantity_symbol = "U" ,
369+ .unit_name = "Volt" ,
370+ .unit_symbol = "V"
371+ },
372+ 540 ,
373+ 270
374+ );
375+ iservicelocator_add (
376+ locator ,
377+ ISERVICELOCATOR_TYPE_SENSOR ,
378+ & sensor_uxb_voltage .iface .interface ,
379+ "uxb-voltage"
380+ );
381+ #endif
355382
356383 #if defined(CONFIG_SERVICE_RADIO_AX5243 ) || defined(CONFIG_SERVICE_RADIO_RFM69 )
357384 gpio_set (GPIOB , GPIO2 );
@@ -539,9 +566,9 @@ int32_t port_init(void) {
539566 #if defined(CONFIG_PLUMPOT_CELLULAR_MQTT_OVER_GSM )
540567
541568 /** @todo generic service move to the system init */
542- mqtt_sensor_upload_init (& mqtt_sensor , & mqtt , "plumpot1 /s" , 120000 );
569+ mqtt_sensor_upload_init (& mqtt_sensor , & mqtt , CONFIG_HOSTNAME " /s" , 120000 );
543570
544- stream_over_mqtt_init (& mqtt_cli_stream , & mqtt , "plumpot1 /cli" , 0 );
571+ stream_over_mqtt_init (& mqtt_cli_stream , & mqtt , CONFIG_HOSTNAME " /cli" , 0 );
545572 stream_over_mqtt_start (& mqtt_cli_stream );
546573 service_cli_init (& mqtt_cli , & (mqtt_cli_stream .stream ), system_cli_tree );
547574 service_cli_start (& mqtt_cli );
0 commit comments