2366 views|3 replies

1412

Posts

3

Resources
The OP
 

[Gizwits Gokit3 Review] Device Access-Step 2: Program Porting [Copy link]

 

1. Write in front

After generating the program template according to the steps of creating a new project ( https://bbs.eeworld.com.cn/thread-1155807-1-1.html ), the program cannot be used at this time and must be transplanted before it can be used.

2. Download the software package

After entering the developer center of Gizwits' official website, click "Download Center" ( https://download.gizwits.com/zh-cn/p/92/93 ), click "GoKit MCU Example Project", select "WeChat Pet House for GoKit 2/3 STM32 V03010101", and click Download.

3. Unzip the downloaded file package

This program file is mainly a driver package, which includes various driver libraries for STM32 and peripheral drivers made by Gizwits.

4. Replace the configuration file

Replace the original configuration file in the automatically generated code with the CubeMX configuration file obtained from the download center:

5. Open the configuration file and regenerate the configuration file

Open the configuration file and click to regenerate the STM32 code for the corresponding configuration.

6. Porting driver code

Copy all the contents in the downloaded folder named "Driver Library Code_CubeMX Version" to the MCU_STM32F103C8x_source/hal file directory.

7. Add the transplanted driver file

After opening the project file, add all the transplanted driver files to the project directory;

8. Add header files

Add the "main.h" header file to the delay.c, hal_infrared.c, hal_motor.c, hal_rgb_led.c, and hal_temp_hum.c files of the driver code

#include "main.h"

9. Add the corresponding function call in the code

(1) Add the header file of the driver library to the MCU_STM32F103C8x_source\Src\main.c and MCU_STM32F103C8x_source\Gizwits\gizwits_product.c files.

#include "delay.h"
#include "hal_motor.h"
#include "hal_rgb_led.h"
#include "hal_temp_hum.h"
#include "hal_infrared.h"

(2) Add the initialization of each sensor in the userInit() function of the MCU_STM32F103C8x_source\Gizwits\gizwits_product.c file.

void userInit(void)
{
    memset((uint8_t *)¤tDataPoint, 0, sizeof(dataPoint_t));
    
    delay_init(72); // 延时 初始化
    rgbLedInit(); // RGB LED 初始化
    dht11Init(); // 温湿度初始化
    irInit(); // 红外初始化
    motorInit(); // 电机初始化
    motorStatus(0); // 电机转速初始化
}

(3) Add the code related to read-only sensor data points in the userHandle() function of the MCU_STM32F103C8x_source\Gizwits\gizwits_product.c file.

void userHandle(void)
{
    uint8_t ret = 0;
    static uint32_t thLastTimer = 0;
    
    ///< 新添加代码: 红外传感器数据获取
    currentDataPoint.valueInfrared = irHandle();
    
    ///< 新添加代码: 温湿度传感器数据获取
    if((gizGetTimerCount() - thLastTimer) > 2000) //上报间隔2S
    {
        ret = dht11Read((uint8_t *)¤tDataPoint.valueTemperature,
                        (uint8_t *)¤tDataPoint.valueHumidity);
        if(ret != 0)
        {
            printf("Failed to read DHT11 [%d] \n", ret);
        }
        
        thLastTimer = gizGetTimerCount();
    }
}

(4) Add the LED lighting code when long/short pressing key2 to the key2ShortPress() function and key2LongPress() function in the MCU_STM32F103C8x_source\User\main.c file.

void key2ShortPress(void)
{
    GIZWITS_LOG("KEY2 PRESS ,Soft AP mode\n");
    #if !MODULE_TYPE
    gizwitsSetMode(WIFI_SOFTAP_MODE);
    #endif
    //Soft AP mode, RGB red
    ledRgbControl(250, 0, 0);
}
void key2LongPress(void)
{
    //AirLink mode
    GIZWITS_LOG("KEY2 PRESS LONG ,AirLink mode\n");
    #if !MODULE_TYPE
    gizwitsSetMode(WIFI_AIRLINK_MODE);
    #endif
    //AirLink mode, RGB Green
    ledRgbControl(0, 250, 0);
}

(5) Add the corresponding code to the gizwitsEventProcess() function in the code\Gizwits\gizwits_product.c (you can add your own application code in the line after the comment //user handle in the code):

The main function of this function is to complete the event processing of write type peripherals.

int8_t gizwitsEventProcess(eventInfo_t *info, uint8_t *gizdata, uint32_t len)
{
  uint8_t i = 0;
  dataPoint_t *dataPointPtr = (dataPoint_t *)gizdata;
  moduleStatusInfo_t *wifiData = (moduleStatusInfo_t *)gizdata;
  protocolTime_t *ptime = (protocolTime_t *)gizdata;
  
#if MODULE_TYPE
  gprsInfo_t *gprsInfoData = (gprsInfo_t *)gizdata;
#else
  moduleInfo_t *ptModuleInfo = (moduleInfo_t *)gizdata;
#endif

  if((NULL == info) || (NULL == gizdata))
  {
    return -1;
  }

  for(i=0; i<info->num; i++)
  {
    switch(info->event[i])
    {
      case EVENT_LED_OnOff:
        currentDataPoint.valueLED_OnOff = dataPointPtr->valueLED_OnOff;
        GIZWITS_LOG("Evt: EVENT_LED_OnOff %d \n", currentDataPoint.valueLED_OnOff);
        if(0x01 == currentDataPoint.valueLED_OnOff)
        {
          //user handle
          ledRgbControl(254, 0, 0);
        }
        else
        {
          //user handle    
	  ledRgbControl(0, 0, 0);
        }
        break;

      case EVENT_LED_Color:
        currentDataPoint.valueLED_Color = dataPointPtr->valueLED_Color;
        GIZWITS_LOG("Evt: EVENT_LED_Color %d\n", currentDataPoint.valueLED_Color);
        switch(currentDataPoint.valueLED_Color)
        {
          case LED_Color_VALUE0:
            //user handle
	    ledRgbControl(currentDataPoint.valueLED_R, currentDataPoint.valueLED_G, 
                          currentDataPoint.valueLED_B);
            break;
          case LED_Color_VALUE1:
            //user handle
	    ledRgbControl(254, 254, 0);
            break;
          case LED_Color_VALUE2:
            //user handle
	    ledRgbControl(254, 0, 70);
            break;
          case LED_Color_VALUE3:
            //user handle
	    ledRgbControl(238, 30, 30);
            break;
          default:
            break;
        }
        break;

      case EVENT_LED_R:
        currentDataPoint.valueLED_R = dataPointPtr->valueLED_R;
        GIZWITS_LOG("Evt:EVENT_LED_R %d\n",currentDataPoint.valueLED_R);
        //user handle
	ledRgbControl(currentDataPoint.valueLED_R, currentDataPoint.valueLED_G, 
		      currentDataPoint.valueLED_B);
        break;
      case EVENT_LED_G:
        currentDataPoint.valueLED_G = dataPointPtr->valueLED_G;
        GIZWITS_LOG("Evt:EVENT_LED_G %d\n",currentDataPoint.valueLED_G);
        //user handle
	ledRgbControl(currentDataPoint.valueLED_R, currentDataPoint.valueLED_G, 
		      currentDataPoint.valueLED_B);
        break;
      case EVENT_LED_B:
        currentDataPoint.valueLED_B = dataPointPtr->valueLED_B;
        GIZWITS_LOG("Evt:EVENT_LED_B %d\n",currentDataPoint.valueLED_B);
        //user handle
	ledRgbControl(currentDataPoint.valueLED_R, currentDataPoint.valueLED_G, 
		      currentDataPoint.valueLED_B);
        break;
      case EVENT_Motor_Speed:
        currentDataPoint.valueMotor_Speed = dataPointPtr->valueMotor_Speed;
        GIZWITS_LOG("Evt:EVENT_Motor_Speed %d\n",currentDataPoint.valueMotor_Speed);
        //user handle
	motorStatus(currentDataPoint.valueMotor_Speed);
        break;


      case WIFI_SOFTAP:
        break;
      case WIFI_AIRLINK:
        break;
      case WIFI_STATION:
        break;
      case WIFI_CON_ROUTER:
	ledRgbControl(0, 0, 0);
        break;
      case WIFI_DISCON_ROUTER:
 
        break;
      case WIFI_CON_M2M:
 
        break;
      case WIFI_DISCON_M2M:
        break;
      case WIFI_RSSI:
        GIZWITS_LOG("RSSI %d\n", wifiData->rssi);
        break;
      case TRANSPARENT_DATA:
        GIZWITS_LOG("TRANSPARENT_DATA \n");
        //user handle , Fetch data from [data] , size is [len]
        break;
      case WIFI_NTP:
        GIZWITS_LOG("WIFI_NTP : [%d-%d-%d %02d:%02d:%02d][%d] \n",ptime->year,ptime->month,
                    ptime->day,ptime->hour,ptime->minute,ptime->second,ptime->ntp);
        break;
      case MODULE_INFO:
            GIZWITS_LOG("MODULE INFO ...\n");
      #if MODULE_TYPE
            GIZWITS_LOG("GPRS MODULE ...\n");
            //Format By gprsInfo_t
      #else
            GIZWITS_LOG("WIF MODULE ...\n");
            //Format By moduleInfo_t
            GIZWITS_LOG("moduleType : [%d] \n",ptModuleInfo->moduleType);
      #endif
    break;
      default:
        break;
    }
  }

  return 0;
}

9. Compile the file

This compiles without errors.

10. The next chapter explains the firmware burning procedure.

This post is from Domestic Chip Exchange

Latest reply

Great! Looking forward to the sequel.   Details Published on 2021-2-3 09:53
Personal signature

没有什么不可以,我就是我,不一样的烟火! 

 
 

7462

Posts

2

Resources
2
 

Thanks for sharing! Looking forward to the follow-up!

This post is from Domestic Chip Exchange

Comments

Continue to update  Details Published on 2021-2-3 08:47
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

1412

Posts

3

Resources
3
 
freebsder posted on 2021-2-2 22:27 Thank you for sharing! Looking forward to the follow-up!

Continue to update

This post is from Domestic Chip Exchange
Personal signature

没有什么不可以,我就是我,不一样的烟火! 

 
 
 

1w

Posts

204

Resources
4
 

Great! Looking forward to the sequel.

This post is from Domestic Chip Exchange
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle
Personal signature

玩板看这里:

https://bbs.eeworld.com.cn/elecplay.html

EEWorld测评频道众多好板等你来玩,还可以来频道许愿树许愿说说你想要玩的板子,我们都在努力为大家实现!

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list