PDL for FM4  Version1.2
Peripheral Driverl Library for FM4
bt.h
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2013 Spansion LLC. All Rights Reserved.
3 *
4 * This software is owned and published by:
5 * Spansion LLC, 915 DeGuigne Dr. Sunnyvale, CA 94088-3453 ("Spansion").
6 *
7 * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
8 * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
9 *
10 * This software contains source code for use with Spansion
11 * components. This software is licensed by Spansion to be adapted only
12 * for use in systems utilizing Spansion components. Spansion shall not be
13 * responsible for misuse or illegal use of this software for devices not
14 * supported herein. Spansion is providing this software "AS IS" and will
15 * not be responsible for issues arising from incorrect user implementation
16 * of the software.
17 *
18 * SPANSION MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
19 * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
20 * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
21 * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
22 * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
23 * WARRANTY OF NONINFRINGEMENT.
24 * SPANSION SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
25 * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
26 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
27 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
28 * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
30 * SAVINGS OR PROFITS,
31 * EVEN IF SPANSION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
33 * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
34 * FROM, THE SOFTWARE.
35 *
36 * This software may be replicated in part or whole for the licensed use,
37 * with the restriction that this Disclaimer and Copyright notice must be
38 * included with each copy of this software, whether used in part or whole,
39 * at all times.
40 */
41 /******************************************************************************/
50 #ifndef __BT_H__
51 #define __BT_H__
52 
53 /******************************************************************************/
54 /* Include files */
55 /******************************************************************************/
56 #include "pdl.h"
57 
58 #if (defined(PDL_PERIPHERAL_BT_ACTIVE))
59 
276 
277 /******************************************************************************
278  * Global definitions
279  ******************************************************************************/
280 #define stc_btn_t FM4_BT_PWM_TypeDef
281 
282 #define BT0 (*((volatile stc_btn_t *) FM4_BT0_PWM_BASE))
283 #define BT1 (*((volatile stc_btn_t *) FM4_BT1_PWM_BASE))
284 #define BT2 (*((volatile stc_btn_t *) FM4_BT2_PWM_BASE))
285 #define BT3 (*((volatile stc_btn_t *) FM4_BT3_PWM_BASE))
286 #define BT4 (*((volatile stc_btn_t *) FM4_BT4_PWM_BASE))
287 #define BT5 (*((volatile stc_btn_t *) FM4_BT5_PWM_BASE))
288 #define BT6 (*((volatile stc_btn_t *) FM4_BT6_PWM_BASE))
289 #define BT7 (*((volatile stc_btn_t *) FM4_BT7_PWM_BASE))
290 #define BT8 (*((volatile stc_btn_t *) FM4_BT8_PWM_BASE))
291 #define BT9 (*((volatile stc_btn_t *) FM4_BT9_PWM_BASE))
292 #define BT10 (*((volatile stc_btn_t *) FM4_BT10_PWM_BASE))
293 #define BT11 (*((volatile stc_btn_t *) FM4_BT11_PWM_BASE))
294 #define BT12 (*((volatile stc_btn_t *) FM4_BT12_PWM_BASE))
295 #define BT13 (*((volatile stc_btn_t *) FM4_BT13_PWM_BASE))
296 #define BT14 (*((volatile stc_btn_t *) FM4_BT14_PWM_BASE))
297 #define BT15 (*((volatile stc_btn_t *) FM4_BT15_PWM_BASE))
298 
299 /******************************************************************************
300  * Global type definitions
301  ******************************************************************************/
307 {
326 
331 typedef enum en_bt_io_mode
332 {
333  BtIoMode0 = 0,
342 
344 
349 typedef enum en_bt_timer_mode
350 {
356 
358 
363 typedef enum en_pwm_clock_pres
364 {
376 
378 
384 {
387 
389 
394 typedef enum en_pwm_output_mask
395 {
398 
400 
405 typedef enum en_pwm_ext_trig
406 {
411 
413 
419 {
422 
424 
429 typedef enum en_pwm_mode
430 {
433 
435 
440 typedef struct stc_bt_pwm_config
441 {
448 
450 
455 typedef enum en_bt_pwm_int
456 {
460 
462 
467 typedef struct stc_pwm_int_sel
468 {
472 
474 
479 typedef struct stc_pwm_int_cb
480 {
484 
486 
491 typedef enum en_ppg_clock_pres
492 {
504 
506 
512 {
515 
517 
522 typedef enum en_ppg_output_mask
523 {
526 
528 
533 typedef enum en_ppg_ext_trig
534 {
539 
541 
547 {
550 
552 
557 typedef enum en_ppg_mode
558 {
561 
563 
568 typedef struct stc_bt_ppg_config
569 {
576 
578 
583 typedef enum en_bt_ppg_int
584 {
587 
589 
594 typedef struct stc_ppg_int_sel
595 {
598 
600 
605 typedef struct stc_ppg_int_cb
606 {
609 
611 
616 typedef enum en_rt_clock_pres
617 {
629 
631 
636 typedef enum en_rt_ext_trigger
637 {
644 
646 
652 {
655 
657 
662 typedef enum en_rt_mode
663 {
664  RtReload = 0,
666 
667 }en_rt_mode_t;
668 
673 typedef enum en_rt_timer_size
674 {
677 
679 
684 typedef struct stc_bt_rt_config
685 {
691 
693 
698 typedef enum en_bt_rt_int
699 {
700  RtTrigInt = 0,
702 
704 
709 typedef struct stc_rt_int_sel
710 {
713 
715 
720 typedef struct stc_rt_int_cb
721 {
724 
726 
731 typedef enum en_pwc_clock_pres
732 {
741 
743 
749 {
755 
757 
762 typedef enum en_pwc_mode
763 {
766 
768 
773 typedef enum en_pwc_timer_size
774 {
777 
779 
784 typedef struct stc_bt_pwc_config
785 {
790 
792 
797 typedef enum en_bt_pwc_int
798 {
801 
803 
808 typedef struct stc_pwc_int_sel
809 {
812 
814 
819 typedef struct stc_pwc_int_cb
820 {
823 
825 
830 typedef struct stc_bt_intern_data
831 {
836 
841 typedef struct stc_bt_instance_data
842 {
846 
847 /******************************************************************************/
848 /* Global variable declarations ('extern', definition in C source) */
849 /******************************************************************************/
852 
853 /******************************************************************************/
854 /* Global function prototypes (definition in C source) */
855 /******************************************************************************/
856 /* C binding of definitions if building with C++ compiler */
857 #ifdef __cplusplus
858 extern "C"
859 {
860 #endif
861 /* 1. Configure BT IO mode */
862 en_result_t Bt_ConfigIOMode(volatile stc_btn_t* pstcBt, en_bt_io_mode_t enIoMode);
863 
864 /* 2. Select BT timer Mode */
865 en_result_t Bt_SelTimerMode(volatile stc_btn_t* pstcBt, en_bt_timer_mode_t enTimerMode);
866 
867 /* 3. Timer configuration */
868 /* 3.1 PWM timer */
869 /* Init */
870 en_result_t Bt_Pwm_Init(volatile stc_btn_t* pstcBt, stc_bt_pwm_config_t* pstcPwmConfig);
871 /* Func/Int Enable/Disable */
872 en_result_t Bt_Pwm_EnableCount(volatile stc_btn_t* pstcBt);
873 en_result_t Bt_Pwm_DisableCount(volatile stc_btn_t* pstcBt);
874 en_result_t Bt_Pwm_EnableSwTrig(volatile stc_btn_t* pstcBt);
875 #if (PDL_INTERRUPT_ENABLE_BT0 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT1 == PDL_ON) || \
876  (PDL_INTERRUPT_ENABLE_BT2 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT3 == PDL_ON) || \
877  (PDL_INTERRUPT_ENABLE_BT4 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT5 == PDL_ON) || \
878  (PDL_INTERRUPT_ENABLE_BT6 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT7 == PDL_ON) || \
879  (PDL_INTERRUPT_ENABLE_BT8 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT9 == PDL_ON) || \
880  (PDL_INTERRUPT_ENABLE_BT10 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT11 == PDL_ON) || \
881  (PDL_INTERRUPT_ENABLE_BT12 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT13 == PDL_ON) || \
882  (PDL_INTERRUPT_ENABLE_BT14 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT15 == PDL_ON)
883 en_result_t Bt_Pwm_EnableInt(volatile stc_btn_t* pstcBt, stc_pwm_int_sel_t* pstcIntSel,
884  stc_pwm_int_cb_t* pstcIntCallback);
885 en_result_t Bt_Pwm_DisableInt(volatile stc_btn_t* pstcBt, stc_pwm_int_sel_t* pstcIntSel);
886 #endif
887 /* Interrupt flag read/clear */
888 en_int_flag_t Bt_Pwm_GetIntFlag(volatile stc_btn_t* pstcBt, en_bt_pwm_int_t enIntType);
889 en_result_t Bt_Pwm_ClrIntFlag(volatile stc_btn_t* pstcBt, en_bt_pwm_int_t enIntType);
890 /* Write/read count */
891 en_result_t Bt_Pwm_WriteCycleVal(volatile stc_btn_t* pstcBt, uint16_t u16Cycle);
892 en_result_t Bt_Pwm_WriteDutyVal(volatile stc_btn_t* pstcBt, uint16_t u16Duty);
893 uint16_t Bt_Pwm_ReadCurCnt(volatile stc_btn_t* pstcBt);
894 
895 /* 3.2 PPG timer */
896 /* Init */
897 en_result_t Bt_Ppg_Init(volatile stc_btn_t* pstcBt, stc_bt_ppg_config_t* pstcPpgConfig);
898 /* Func/Int Enable/Disable */
899 en_result_t Bt_Ppg_EnableCount(volatile stc_btn_t* pstcBt);
900 en_result_t Bt_Ppg_DisableCount(volatile stc_btn_t* pstcBt);
901 en_result_t Bt_Ppg_EnableSwTrig(volatile stc_btn_t* pstcBt);
902 #if (PDL_INTERRUPT_ENABLE_BT0 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT1 == PDL_ON) || \
903  (PDL_INTERRUPT_ENABLE_BT2 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT3 == PDL_ON) || \
904  (PDL_INTERRUPT_ENABLE_BT4 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT5 == PDL_ON) || \
905  (PDL_INTERRUPT_ENABLE_BT6 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT7 == PDL_ON) || \
906  (PDL_INTERRUPT_ENABLE_BT8 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT9 == PDL_ON) || \
907  (PDL_INTERRUPT_ENABLE_BT10 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT11 == PDL_ON) || \
908  (PDL_INTERRUPT_ENABLE_BT12 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT13 == PDL_ON) || \
909  (PDL_INTERRUPT_ENABLE_BT14 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT15 == PDL_ON)
910 en_result_t Bt_Ppg_EnableInt(volatile stc_btn_t* pstcBt, stc_ppg_int_sel_t* pstcIntSel,
911  stc_ppg_int_cb_t* pstcIntCallback);
912 en_result_t Bt_Ppg_DisableInt(volatile stc_btn_t* pstcBt, stc_ppg_int_sel_t* pstcIntSel);
913 #endif
914 /* Interrupt flag read/clear */
915 en_int_flag_t Bt_Ppg_GetIntFlag(volatile stc_btn_t* pstcBt, en_bt_ppg_int_t enIntType);
916 en_result_t Bt_Ppg_ClrIntFlag(volatile stc_btn_t* pstcBt, en_bt_ppg_int_t enIntType);
917 /* Write/read count */
918 en_result_t Bt_Ppg_WriteLowWidthVal(volatile stc_btn_t* pstcBt, uint16_t u16Val);
919 en_result_t Bt_Ppg_WriteHighWidthVal(volatile stc_btn_t* pstcBt, uint16_t u16Val);
920 uint16_t Bt_Ppg_ReadCurCnt(volatile stc_btn_t* pstcBt);
921 
922 /* 3.3 RT timer */
923 /* Init */
924 en_result_t Bt_Rt_Init(volatile stc_btn_t* pstcBt, stc_bt_rt_config_t* pstcRtConfig);
925 /* Func/Int Enable/Disable */
926 en_result_t Bt_Rt_EnableCount(volatile stc_btn_t* pstcBt);
927 en_result_t Bt_Rt_DisableCount(volatile stc_btn_t* pstcBt);
928 en_result_t Bt_Rt_EnableSwTrig(volatile stc_btn_t* pstcBt);
929 #if (PDL_INTERRUPT_ENABLE_BT0 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT1 == PDL_ON) || \
930  (PDL_INTERRUPT_ENABLE_BT2 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT3 == PDL_ON) || \
931  (PDL_INTERRUPT_ENABLE_BT4 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT5 == PDL_ON) || \
932  (PDL_INTERRUPT_ENABLE_BT6 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT7 == PDL_ON) || \
933  (PDL_INTERRUPT_ENABLE_BT8 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT9 == PDL_ON) || \
934  (PDL_INTERRUPT_ENABLE_BT10 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT11 == PDL_ON) || \
935  (PDL_INTERRUPT_ENABLE_BT12 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT13 == PDL_ON) || \
936  (PDL_INTERRUPT_ENABLE_BT14 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT15 == PDL_ON)
937 en_result_t Bt_Rt_EnableInt(volatile stc_btn_t* pstcBt, stc_rt_int_sel_t* pstcIntSel,
938  stc_rt_int_cb_t* pstcIntCallback);
939 en_result_t Bt_Rt_DisableInt(volatile stc_btn_t* pstcBt, stc_rt_int_sel_t* pstcIntSel);
940 #endif
941 /* Interrupt flag read/clear */
942 en_int_flag_t Bt_Rt_GetIntFlag(volatile stc_btn_t* pstcBt, en_bt_rt_int_t enIntType);
943 en_result_t Bt_Rt_ClrIntFlag(volatile stc_btn_t* pstcBt, en_bt_rt_int_t enIntType);
944 /* Write/read count */
945 en_result_t Bt_Rt_WriteCycleVal(volatile stc_btn_t* pstcBt, uint16_t u16Val);
946 uint16_t Bt_Rt_ReadCurCnt(volatile stc_btn_t* pstcBt);
947 
948 /* 3.4 PWC timer */
949 /* Init */
950 en_result_t Bt_Pwc_Init(volatile stc_btn_t* pstcBt, stc_bt_pwc_config_t* pstcPwcConfig);
951 /* Func/Int Enable/Disable */
952 en_result_t Bt_Pwc_EnableCount(volatile stc_btn_t* pstcBt);
953 en_result_t Bt_Pwc_DisableCount(volatile stc_btn_t* pstcBt);
954 #if (PDL_INTERRUPT_ENABLE_BT0 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT1 == PDL_ON) || \
955  (PDL_INTERRUPT_ENABLE_BT2 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT3 == PDL_ON) || \
956  (PDL_INTERRUPT_ENABLE_BT4 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT5 == PDL_ON) || \
957  (PDL_INTERRUPT_ENABLE_BT6 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT7 == PDL_ON) || \
958  (PDL_INTERRUPT_ENABLE_BT8 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT9 == PDL_ON) || \
959  (PDL_INTERRUPT_ENABLE_BT10 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT11 == PDL_ON) || \
960  (PDL_INTERRUPT_ENABLE_BT12 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT13 == PDL_ON) || \
961  (PDL_INTERRUPT_ENABLE_BT14 == PDL_ON) || (PDL_INTERRUPT_ENABLE_BT15 == PDL_ON)
962 en_result_t Bt_Pwc_EnableInt(volatile stc_btn_t* pstcBt, stc_pwc_int_sel_t* pstcIntSel,
963  stc_pwc_int_cb_t* pstcIntCallback);
964 en_result_t Bt_Pwc_DisableInt(volatile stc_btn_t* pstcBt, stc_pwc_int_sel_t* pstcIntSel);
965 #endif
966 /* Interrupt flag read/clear */
967 en_int_flag_t Bt_Pwc_GetIntFlag(volatile stc_btn_t* pstcBt, en_bt_pwc_int_t enIntType);
968 en_result_t Bt_Pwc_ClrIntFlag(volatile stc_btn_t* pstcBt, en_bt_pwc_int_t enIntType);
970 /* Write/read count */
971 uint16_t Bt_Pwc_Get16BitMeasureData(volatile stc_btn_t* pstcBt);
972 uint32_t Bt_Pwc_Get32BitMeasureData(volatile stc_btn_t* pstcBt);
973 
974 /* 4. IRQ handler */
975 void Bt_IrqHandler( volatile stc_btn_t* pstcBt,
976  stc_bt_intern_data_t* pstcBtInternData) ;
977 /* 5. Start/stop BT simultaneously */
978 void Bt_SetSimultaneousStart(uint16_t u16Value);
979 
981 #ifdef __cplusplus
982 }
983 #endif
984 
985 #endif // #if (defined(PDL_PERIPHERAL_BT_ACTIVE))
986 
987 #endif // #if __BT_H__
988 /******************************************************************************/
989 /* EOF (not truncated) */
990 /******************************************************************************/