luat_init_w60x.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "luat_base.h"
  2. #include "luat_malloc.h"
  3. #include "luat_msgbus.h"
  4. #include "luat_timer.h"
  5. #include "luat_gpio.h"
  6. #include "luat_fs.h"
  7. #include "rtthread.h"
  8. #include <rtdevice.h>
  9. #ifdef RT_USING_WIFI
  10. #include "wlan_mgnt.h"
  11. #endif
  12. #define DBG_TAG "w60x.init"
  13. #define DBG_LVL DBG_LOG
  14. #include <rtdbg.h>
  15. #ifdef BSP_USING_WM_LIBRARIES
  16. static int w60x_read_cfg(void *buff, int len) {
  17. int fd = luat_fs_fopen("/wlan.cfg", "rb");
  18. if (fd) {
  19. luat_fs_fread(buff, 1, len, fd);
  20. luat_fs_fclose(fd);
  21. return len;
  22. }
  23. return 0;
  24. };
  25. static int w60x_get_len(void) {
  26. return luat_fs_fsize("/wlan.cfg");
  27. };
  28. static int w60x_write_cfg(void *buff, int len) {
  29. int fd = luat_fs_fopen("/wlan.cfg", "w");
  30. if (fd) {
  31. luat_fs_fwrite(buff, 1, len, fd);
  32. luat_fs_fclose(fd);
  33. return len;
  34. }
  35. return 0;
  36. };
  37. static struct rt_wlan_cfg_ops cfg_ops = {
  38. w60x_read_cfg,
  39. w60x_get_len,
  40. w60x_write_cfg
  41. };
  42. static rt_err_t w600_bt(void *context) {
  43. rt_kprintf("\r\nFUCK!!\r\n");
  44. return 0;
  45. }
  46. static int rtt_w60x_init() {
  47. #ifdef RT_USING_WIFI
  48. rt_wlan_set_mode("wlan0", RT_WLAN_STATION);
  49. rt_wlan_cfg_set_ops(&cfg_ops);
  50. rt_wlan_cfg_cache_refresh();
  51. #endif
  52. rt_hw_exception_install(w600_bt);
  53. return RT_EOK;
  54. }
  55. INIT_COMPONENT_EXPORT(rtt_w60x_init);
  56. #endif