⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lh7a400_bmi_driver.c

📁 sharp触摸屏测试代码
💻 C
字号:
/**********************************************************************
 * $Workfile:   LH7A400_bmi_driver.c  $
 * $Revision:   1.0  $
 * $Author:   MaysR  $
 * $Date:   16 Apr 2002 16:37:04  $
 *
 * Project: LHA7400 Battery Monitor Interface driver
 *
 * Description:
 *
 * Global Include Files:
 *    SMA_types.h
 *    LH7A400_bmi_driver.h
 *
 * Local Include Files:
 *
 * Revision History:
 * $Log:
 *
 * COPYRIGHT (C) 2001, SHARP MICROELECTRONICS OF THE AMERICAS, INC.
 *                     CAMAS, WA
 *********************************************************************/

#include "LH7A400_bmi_driver.h"
#include "LH7A400_bmi_params.h"
#include "bq2050H_params.h"

void initialize_swi(UNS_8 device)
{
   BMISWI->swicr = (SWICR_RDSS(swi_settings[device].read_size) |
         SWICR_WDCS(swi_settings[device].write_size) |
         ((swi_settings[device].ss_invert) ? SWICR_SP_INVERT : 0) |
         ((swi_settings[device].data_invert) ? SWICR_SWIDINV : 0));
   bmi_swi_enable();
   bmi_swi_break(device);
   bmi_swi_fillstruct();
}

void bmi_swi_fillstruct(void)
{
   UNS_8 *member;
   UNS_8 i;

   member = (UNS_8 *)&BQ2050HREGS;
   for (i = 1; i < sizeof(BQ2050HREGS); i++) {
      if (i == 0xa || i == 0x14 || i == 0x16)
         i++;
      else if (i == 0x19 || i == 0x3a)
         i += 5;
      else if (i == 0x1f)
         i += 25;
      bmi_swi_send_data(i);      //need to expand this function
      while (BMISWI->swirsr.swirisr == 0);   // temp delay for transmit
      BMISWI->swirsr.swirisr = SWIRISR_RWTIS; // need to clear the tx flag
      while (!(BMISWI->swisr && SWISR_WRF)); // wait for rx data
      member[i - 1] = bmi_swi_recv_data(); // read rx data
   }
}

void bmi_swi_enable(void)
{
   BMISWI->swicr |= SWICR_SWIEN;
}

void bmi_swi_disable(void)
{
   BMISWI->swicr &= ~(SWICR_SWIEN);
}

void bmi_swi_break(UNS_8 device)
{
   BMISWI->swibr = (SWIBR_BT(swi_settings[device].break_time) |
            SWIBR_BRT(swi_settings[device].break_recovery));
   BMISWI->switr = 0;
   BMISWI->swicr |= SWICR_GBS;
   while (BMISWI->swirsr.swirisr == 0); //need interrupt handler here
   BMISWI->swirsr.swirisr = 4;   //need to code to test and clear condition
   BMISWI->swibr = 0;
   BMISWI->switr = SWITR_BTG(swi_settings[device].bit_time_gen);
   BMISWI->swicr &= ~(SWICR_GBS);
}

void bmi_swi_data_invert(void)
{
   BMISWI->swicr |= SWICR_SWIDINV;
}

void bmi_swi_data_normal(void)
{
   BMISWI->swicr &= ~(SWICR_SWIDINV);
}

void bmi_swi_read_size(UNS_32 size)
{
   BMISWI->swicr |= SWICR_RDSS(size);
}

void bmi_swi_write_size(UNS_32 size)
{
   BMISWI->swicr |= SWICR_WDCS(size);
}

void bmi_swi_transfer_reset(void)
{
   BMISWI->swicr |= SWICR_T_RST;
}

void bmi_swi_stop_start_invert(void)
{
   BMISWI->swicr |= SWICR_SP_INVERT;
}

void bmi_swi_stop_start_normal(void)
{
   BMISWI->swicr &= ~(SWICR_SP_INVERT);
}

void bmi_swi_send_data(UNS_32 data)
{
   BMISWI->swidr = data;
}

UNS_32 bmi_swi_recv_data(void)
{
   UNS_32 status;

   status = bmi_swi_status();
   if (status && SWISR_WRF)
      return BMISWI->swidr;
   else
      return -1;
}

UNS_32 bmi_swi_status(void)
{
   return BMISWI->swisr;
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -