Revision 4c72a54c modules/LightRing_1-2/module.c

View differences:

modules/LightRing_1-2/module.c
298 298
  /* GPIO */ &_gpioLed,
299 299
  /* meta */ {
300 300
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
301
    /* active state   */ LED_LLD_GPIO_ACTIVE_STATE,
301
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
302 302
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
303 303
  },
304 304
};
......
461 461
  /* power enable GPIO  */ &moduleGpioSwVsysEn,
462 462
};
463 463

  
464
// TODO: add SNx5C3221E
465

  
464 466
TLC5947Driver moduleLldLedPwm = {
465 467
  /* SPI driver         */ &MODULE_HAL_SPI_LIGHT,
466 468
  /* BLANK signal GPIO  */ &moduleGpioLightBlank,
......
471 473

  
472 474
/*===========================================================================*/
473 475
/**
474
 * @name Unit tests (UT)
476
 * @name Tests
475 477
 * @{
476 478
 */
477 479
/*===========================================================================*/
478 480
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
479
#include <string.h>
480 481

  
481 482
/*
482
 * EEPROM (AT24C01B)
483
 * AT24C01BN-SH-B (EEPROM)
483 484
 */
484
static int _utShellCmdCb_AlldAt24c01b(BaseSequentialStream* stream, int argc, char* argv[])
485
#include <module_test_AT24C01B.h>
486
static int _testAt24co1bShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
485 487
{
486
  (void)argc;
487
  (void)argv;
488
  aosUtRun(stream, &moduleUtAlldAt24c01b, NULL);
489
  return AOS_OK;
488
  return moduleTestAt24c01bShellCb(stream, argc, argv, NULL);
490 489
}
491
static ut_at24c01bdata_t _utAlldAt24c01bData = {
492
  /* driver   */ &moduleLldEeprom,
493
  /* timeout  */ MICROSECONDS_PER_SECOND,
494
};
495
aos_unittest_t moduleUtAlldAt24c01b = {
496
  /* name           */ "AT24C01B",
497
  /* info           */ "1kbit EEPROM",
498
  /* test function  */ utAlldAt24c01bFunc,
499
  /* shell command  */ {
500
    /* name     */ "unittest:EEPROM",
501
    /* callback */ _utShellCmdCb_AlldAt24c01b,
502
    /* next     */ NULL,
503
  },
504
  /* data           */ &_utAlldAt24c01bData,
505
};
490
AOS_SHELL_COMMAND(moduleTestAt24c01bShellCmd, "test:EEPROM", _testAt24co1bShellCmdCb);
506 491

  
507 492
/*
508 493
 * INA219 (power monitor)
509 494
 */
510
static int _utShellCmdCb_AlldIna219(BaseSequentialStream* stream, int argc, char* argv[])
495
#include <module_test_INA219.h>
496
static int _testIna219ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
511 497
{
512
  (void)argc;
513
  (void)argv;
514
  aosUtRun(stream, &moduleUtAlldIna219, "VLED (4.2V)");
515
  return AOS_OK;
498
  return moduleTestIna219ShellCb(stream, argc, argv, NULL);
516 499
}
517
static ut_ina219data_t _utIna219Data = {
518
  /* driver           */ &moduleLldPowerMonitorVled,
519
  /* expected voltage */ 4.2f,
520
  /* tolerance        */ 0.2f,
521
  /* timeout */ MICROSECONDS_PER_SECOND,
522
};
523
aos_unittest_t moduleUtAlldIna219 = {
524
  /* name           */ "INA219",
525
  /* info           */ "power monitor",
526
  /* test function  */ utAlldIna219Func,
527
  /* shell command  */ {
528
    /* name     */ "unittest:PowerMonitor",
529
    /* callback */ _utShellCmdCb_AlldIna219,
530
    /* next     */ NULL,
531
  },
532
  /* data           */ &_utIna219Data,
533
};
500
AOS_SHELL_COMMAND(moduleTestIna219ShellCmd, "test:PowerMonitor", _testIna219ShellCmdCb);
534 501

  
535 502
/*
536 503
 * Status LED
537 504
 */
538
static int _utShellCmdCb_AlldLed(BaseSequentialStream* stream, int argc, char* argv[])
505
#include <module_test_LED.h>
506
static int _testLedShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
539 507
{
540
  (void)argc;
541
  (void)argv;
542
  aosUtRun(stream, &moduleUtAlldLed, NULL);
543
  return AOS_OK;
508
  return moduleTestLedShellCb(stream, argc, argv, NULL);
544 509
}
545
aos_unittest_t moduleUtAlldLed = {
546
  /* name           */ "LED",
547
  /* info           */ NULL,
548
  /* test function  */ utAlldLedFunc,
549
  /* shell command  */ {
550
    /* name     */ "unittest:StatusLED",
551
    /* callback */ _utShellCmdCb_AlldLed,
552
    /* next     */ NULL,
553
  },
554
  /* data           */ &moduleLldStatusLed,
555
};
510
AOS_SHELL_COMMAND(moduleTestLedShellCmd, "test:StatusLED", _testLedShellCmdCb);
556 511

  
557 512
/*
558
 * Power switch driver (MIC9404x)
513
 * MIC9404x (power switch)
559 514
 */
560
static int _utShellCmdCb_Mic9404x(BaseSequentialStream* stream, int argc, char* argv[])
515
#include <module_test_MIC9404x.h>
516
static int _testMic9404xShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
561 517
{
562
  // evaluate arguments
563
  if (argc == 2) {
564
    if (strcmp(argv[1], "1.8V") == 0) {
565
      moduleUtAlldMic9404x.data = &moduleLldPowerSwitchV18;
566
      aosUtRun(stream, &moduleUtAlldMic9404x, "1.8V");
567
      moduleUtAlldMic9404x.data = NULL;
568
      return AOS_OK;
569
    }
570
    else if (strcmp(argv[1], "3.3V") == 0) {
571
      moduleUtAlldMic9404x.data = &moduleLldPowerSwitchV33;
572
      aosUtRun(stream, &moduleUtAlldMic9404x, "3.3V");
573
      moduleUtAlldMic9404x.data = NULL;
574
      return AOS_OK;
575
    }
576
// The 4.2V switch is disabled due to a hardware bug.
577
//    else if (strcmp(argv[1], "4.2V") == 0) {
578
//      moduleUtAlldMic9404x.data = &moduleLldPowerSwitchV42;
579
//      aosUtRun(stream, &moduleUtAlldMic9404x, "4.2V");
580
//      moduleUtAlldMic9404x.data = NULL;
581
//      return AOS_OK;
582
//    }
583
    else if (strcmp(argv[1], "5.0V") == 0) {
584
      moduleUtAlldMic9404x.data = &moduleLldPowerSwitchV50;
585
      aosUtRun(stream, &moduleUtAlldMic9404x, "5.0V");
586
      moduleUtAlldMic9404x.data = NULL;
587
      return AOS_OK;
588
    }
589
    else if (strcmp(argv[1], "VSYS") == 0) {
590
      moduleUtAlldMic9404x.data = &moduleLldPowerSwitchVsys;
591
      aosUtRun(stream, &moduleUtAlldMic9404x, "VSYS");
592
      moduleUtAlldMic9404x.data = NULL;
593
      return AOS_OK;
594
    }
595
  }
596
  // print help
597
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
598
  chprintf(stream, "Options:\n");
599
  chprintf(stream, "  1.8V\n");
600
  chprintf(stream, "    Test power switch for 1.8V supply.\n");
601
  chprintf(stream, "  3.3V\n");
602
  chprintf(stream, "    Test power switch for 3.3V supply.\n");
603
// The 4.2V switch is disabled due to a hardware bug.
604
//  chprintf(stream, "  4.2V\n");
605
//  chprintf(stream, "    Test power switch for 4.2V supply.\n");
606
  chprintf(stream, "  5.0V\n");
607
  chprintf(stream, "    Test power switch for 5.0V supply.\n");
608
  chprintf(stream, "  VSYS\n");
609
  chprintf(stream, "    Test power switch for VSYS supply.\n");
610
  return AOS_INVALIDARGUMENTS;
518
  return moduleTestMic9404xShellCb(stream, argc, argv, NULL);
611 519
}
612
aos_unittest_t moduleUtAlldMic9404x = {
613
  /* info           */ "MIC9404x",
614
  /* name           */ "power swicth driver",
615
  /* test function  */ utAlldMic9404xFunc,
616
  /* shell command  */ {
617
    /* name     */ "unittest:PowerSwitch",
618
    /* callback */ _utShellCmdCb_Mic9404x,
619
    /* next     */ NULL,
620
  },
621
  /* data           */ NULL,
622
};
520
AOS_SHELL_COMMAND(moduleTestMic9404xShellCmd, "test:PowerSwitch", _testMic9404xShellCmdCb);
521

  
522
// TODO: add SNx5C3221E
523

  
524
/*
525
 * TLC5947 (24 channel PWM LED driver)
526
 */
527
#include <module_test_TLC5947.h>
528
static int _testTlc5947ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
529
{
530
  return moduleTestTlc5947ShellCb(stream, argc, argv, NULL);
531
}
532
AOS_SHELL_COMMAND(moduleTestTlc5947ShellCmd, "test:Lights", _testTlc5947ShellCmdCb);
623 533

  
624 534
/*
625
 * LED PWM driver (TLC5947)
535
 * entire module
626 536
 */
627
static int _utShellCmdCb_Tlc5947(BaseSequentialStream* stream, int argc, char* argv[])
537
static int _testAllShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
628 538
{
629 539
  (void)argc;
630 540
  (void)argv;
631
  aosUtRun(stream, &moduleUtAlldTlc5947, NULL);
632
  return AOS_OK;
541

  
542
  int status = AOS_OK;
543
  char* targv[AMIROOS_CFG_SHELL_MAXARGS] = {NULL};
544
  aos_testresult_t result_test = {0, 0};
545
  aos_testresult_t result_total = {0, 0};
546

  
547
  /* AT24C01B (EEPROM) */
548
  status |= moduleTestAt24c01bShellCb(stream, 0, targv, &result_test);
549
  result_total = aosTestResultAdd(result_total, result_test);
550

  
551
  /* INA219 (power monitor) */
552
  status |= moduleTestIna219ShellCb(stream, 0, targv, &result_test);
553
  result_total = aosTestResultAdd(result_total, result_test);
554

  
555
  /* Status LED */
556
  status |= moduleTestLedShellCb(stream, 0, targv, &result_test);
557
  result_total = aosTestResultAdd(result_total, result_test);
558

  
559
  /* MIC9404x (power switch) */
560
  // 1.8V
561
  targv[1] = "1.8V";
562
  status |= moduleTestMic9404xShellCb(stream, 2, targv, &result_test);
563
  result_total = aosTestResultAdd(result_total, result_test);
564
  // 3.3V
565
  targv[1] = "3.3V";
566
  status |= moduleTestMic9404xShellCb(stream, 2, targv, &result_test);
567
  result_total = aosTestResultAdd(result_total, result_test);
568
// The 4.2V switch is disabled due to a hardware bug.
569
//  // 4.2V
570
//  targv[1] = "4.2V";
571
//  status |= moduleTestMic9404xShellCb(stream, 2, targv, &result_test);
572
//  result_total = aosTestResultAdd(result_total, result_test);
573
  // 5.0V
574
  targv[1] = "5.0V";
575
  status |= moduleTestMic9404xShellCb(stream, 2, targv, &result_test);
576
  result_total = aosTestResultAdd(result_total, result_test);
577
  //VSYS
578
  targv[1] = "VSYS";
579
  status |= moduleTestMic9404xShellCb(stream, 2, targv, &result_test);
580
  result_total = aosTestResultAdd(result_total, result_test);
581
  targv[1] = "";
582

  
583
  // TODO: add SNx5C3221E
584

  
585
  /* TLC5947 (24 channel PWM LED driver) */
586
  status |= moduleTestTlc5947ShellCb(stream, 0, targv, &result_test);
587
  result_total = aosTestResultAdd(result_total, result_test);
588

  
589
  // print total result
590
  chprintf(stream, "\n");
591
  aosTestResultPrintSummary(stream, &result_total, "entire module");
592

  
593
  return status;
633 594
}
634
aos_unittest_t moduleUtAlldTlc5947 = {
635
  /* info           */ "TLC5947",
636
  /* name           */ "LED PWM driver",
637
  /* test function  */ utAlldTlc5947Func,
638
  /* shell command  */ {
639
    /* name     */ "unittest:Lights",
640
    /* callback */ _utShellCmdCb_Tlc5947,
641
    /* next     */ NULL,
642
  },
643
  /* data           */ &moduleLldLedPwm,
644
};
595
AOS_SHELL_COMMAND(moduleTestAllShellCmd, "test:all", _testAllShellCmdCb);
596

  
597

  
598

  
599

  
600
//#include <string.h>
601

  
602
///*
603
// * EEPROM (AT24C01B)
604
// */
605
//static int _utShellCmdCb_AlldAt24c01b(BaseSequentialStream* stream, int argc, char* argv[])
606
//{
607
//  (void)argc;
608
//  (void)argv;
609
//  aosUtRun(stream, &moduleUtAlldAt24c01b, NULL);
610
//  return AOS_OK;
611
//}
612
//static ut_at24c01bdata_t _utAlldAt24c01bData = {
613
//  /* driver   */ &moduleLldEeprom,
614
//  /* timeout  */ MICROSECONDS_PER_SECOND,
615
//};
616
//aos_unittest_t moduleUtAlldAt24c01b = {
617
//  /* name           */ "AT24C01B",
618
//  /* info           */ "1kbit EEPROM",
619
//  /* test function  */ utAlldAt24c01bFunc,
620
//  /* shell command  */ {
621
//    /* name     */ "unittest:EEPROM",
622
//    /* callback */ _utShellCmdCb_AlldAt24c01b,
623
//    /* next     */ NULL,
624
//  },
625
//  /* data           */ &_utAlldAt24c01bData,
626
//};
627

  
628
///*
629
// * INA219 (power monitor)
630
// */
631
//static int _utShellCmdCb_AlldIna219(BaseSequentialStream* stream, int argc, char* argv[])
632
//{
633
//  (void)argc;
634
//  (void)argv;
635
//  aosUtRun(stream, &moduleUtAlldIna219, "VLED (4.2V)");
636
//  return AOS_OK;
637
//}
638
//static ut_ina219data_t _utIna219Data = {
639
//  /* driver           */ &moduleLldPowerMonitorVled,
640
//  /* expected voltage */ 4.2f,
641
//  /* tolerance        */ 0.2f,
642
//  /* timeout */ MICROSECONDS_PER_SECOND,
643
//};
644
//aos_unittest_t moduleUtAlldIna219 = {
645
//  /* name           */ "INA219",
646
//  /* info           */ "power monitor",
647
//  /* test function  */ utAlldIna219Func,
648
//  /* shell command  */ {
649
//    /* name     */ "unittest:PowerMonitor",
650
//    /* callback */ _utShellCmdCb_AlldIna219,
651
//    /* next     */ NULL,
652
//  },
653
//  /* data           */ &_utIna219Data,
654
//};
655

  
656
///*
657
// * Status LED
658
// */
659
//static int _utShellCmdCb_AlldLed(BaseSequentialStream* stream, int argc, char* argv[])
660
//{
661
//  (void)argc;
662
//  (void)argv;
663
//  aosUtRun(stream, &moduleUtAlldLed, NULL);
664
//  return AOS_OK;
665
//}
666
//aos_unittest_t moduleUtAlldLed = {
667
//  /* name           */ "LED",
668
//  /* info           */ NULL,
669
//  /* test function  */ utAlldLedFunc,
670
//  /* shell command  */ {
671
//    /* name     */ "unittest:StatusLED",
672
//    /* callback */ _utShellCmdCb_AlldLed,
673
//    /* next     */ NULL,
674
//  },
675
//  /* data           */ &moduleLldStatusLed,
676
//};
677

  
678
///*
679
// * Power switch driver (MIC9404x)
680
// */
681
//static int _utShellCmdCb_Mic9404x(BaseSequentialStream* stream, int argc, char* argv[])
682
//{
683
//  // evaluate arguments
684
//  if (argc == 2) {
685
//    if (strcmp(argv[1], "1.8V") == 0) {
686
//      moduleUtAlldMic9404x.data = &moduleLldPowerSwitchV18;
687
//      aosUtRun(stream, &moduleUtAlldMic9404x, "1.8V");
688
//      moduleUtAlldMic9404x.data = NULL;
689
//      return AOS_OK;
690
//    }
691
//    else if (strcmp(argv[1], "3.3V") == 0) {
692
//      moduleUtAlldMic9404x.data = &moduleLldPowerSwitchV33;
693
//      aosUtRun(stream, &moduleUtAlldMic9404x, "3.3V");
694
//      moduleUtAlldMic9404x.data = NULL;
695
//      return AOS_OK;
696
//    }
697
//// The 4.2V switch is disabled due to a hardware bug.
698
////    else if (strcmp(argv[1], "4.2V") == 0) {
699
////      moduleUtAlldMic9404x.data = &moduleLldPowerSwitchV42;
700
////      aosUtRun(stream, &moduleUtAlldMic9404x, "4.2V");
701
////      moduleUtAlldMic9404x.data = NULL;
702
////      return AOS_OK;
703
////    }
704
//    else if (strcmp(argv[1], "5.0V") == 0) {
705
//      moduleUtAlldMic9404x.data = &moduleLldPowerSwitchV50;
706
//      aosUtRun(stream, &moduleUtAlldMic9404x, "5.0V");
707
//      moduleUtAlldMic9404x.data = NULL;
708
//      return AOS_OK;
709
//    }
710
//    else if (strcmp(argv[1], "VSYS") == 0) {
711
//      moduleUtAlldMic9404x.data = &moduleLldPowerSwitchVsys;
712
//      aosUtRun(stream, &moduleUtAlldMic9404x, "VSYS");
713
//      moduleUtAlldMic9404x.data = NULL;
714
//      return AOS_OK;
715
//    }
716
//  }
717
//  // print help
718
//  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
719
//  chprintf(stream, "Options:\n");
720
//  chprintf(stream, "  1.8V\n");
721
//  chprintf(stream, "    Test power switch for 1.8V supply.\n");
722
//  chprintf(stream, "  3.3V\n");
723
//  chprintf(stream, "    Test power switch for 3.3V supply.\n");
724
//// The 4.2V switch is disabled due to a hardware bug.
725
////  chprintf(stream, "  4.2V\n");
726
////  chprintf(stream, "    Test power switch for 4.2V supply.\n");
727
//  chprintf(stream, "  5.0V\n");
728
//  chprintf(stream, "    Test power switch for 5.0V supply.\n");
729
//  chprintf(stream, "  VSYS\n");
730
//  chprintf(stream, "    Test power switch for VSYS supply.\n");
731
//  return AOS_INVALIDARGUMENTS;
732
//}
733
//aos_unittest_t moduleUtAlldMic9404x = {
734
//  /* info           */ "MIC9404x",
735
//  /* name           */ "power swicth driver",
736
//  /* test function  */ utAlldMic9404xFunc,
737
//  /* shell command  */ {
738
//    /* name     */ "unittest:PowerSwitch",
739
//    /* callback */ _utShellCmdCb_Mic9404x,
740
//    /* next     */ NULL,
741
//  },
742
//  /* data           */ NULL,
743
//};
744

  
745
///*
746
// * LED PWM driver (TLC5947)
747
// */
748
//static int _utShellCmdCb_Tlc5947(BaseSequentialStream* stream, int argc, char* argv[])
749
//{
750
//  (void)argc;
751
//  (void)argv;
752
//  aosUtRun(stream, &moduleUtAlldTlc5947, NULL);
753
//  return AOS_OK;
754
//}
755
//aos_unittest_t moduleUtAlldTlc5947 = {
756
//  /* info           */ "TLC5947",
757
//  /* name           */ "LED PWM driver",
758
//  /* test function  */ utAlldTlc5947Func,
759
//  /* shell command  */ {
760
//    /* name     */ "unittest:Lights",
761
//    /* callback */ _utShellCmdCb_Tlc5947,
762
//    /* next     */ NULL,
763
//  },
764
//  /* data           */ &moduleLldLedPwm,
765
//};
645 766

  
646 767
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
647 768

  

Also available in: Unified diff