// 7350IntDlg.cpp : implementation file // #include "stdafx.h" #include "7350Int.h" #include "7350IntDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support // Implementation protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) END_MESSAGE_MAP() // C7350IntDlg dialog C7350IntDlg::C7350IntDlg(I16 hCard, CWnd* pParent /*=NULL*/) : CDialog(C7350IntDlg::IDD, pParent) , m_dwI2CSlaveAddr(80) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_hCard = hCard; m_dwOutVal = 0x00000000; m_PatType = 0; } void C7350IntDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Text(pDX, IDC_EDIT_I2C_ADDR, m_dwI2CSlaveAddr); } BEGIN_MESSAGE_MAP(C7350IntDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_WM_DESTROY() // ON_WM_TIMER() ON_BN_CLICKED(IDC_BT_START, &C7350IntDlg::OnStart) ON_BN_CLICKED(IDC_RADIO_INC, &C7350IntDlg::OnBnClickedRadioInc) ON_BN_CLICKED(IDC_RADIO_DEC, &C7350IntDlg::OnBnClickedRadioDec) END_MESSAGE_MAP() // C7350IntDlg message handlers BOOL C7350IntDlg::OnInitDialog() { CString strTemp; CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { BOOL bNameValid; CString strAboutMenu; bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); ASSERT(bNameValid); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon m_PatType = 0; ((CButton*)GetDlgItem( IDC_RADIO_INC ))->SetCheck( TRUE ); // TODO: Add extra initialization here I16 err; /* * Set AFI voltage level * AFI0/AFI1 will be set to I2C mode automatically if I2C is enabled. */ err = DIO_VoltLevelConfig(m_hCard, P7350_PortAFI, VoltLevel_3R3); if(err!=NoError) { strTemp.Format( TEXT("DIO_VoltLevelConfig() Error = %d"), err); AfxMessageBox( strTemp ); return TRUE; } /*Setup I2C*/ err = I2C_Setup( m_hCard, I2C_Port_A, /*I2C port to be set*/ 0, /*Not used in 7350*/ 0xff, /*The parameter is used to set Pre-clock in 7350*/ 0 /*Not used in 7350*/ ); if(err!=NoError) { strTemp.Format( TEXT("I2C_Setup() Error = %d"), err); AfxMessageBox( strTemp ); return TRUE; } /* * Enable I2C * AFI0/AFI1 will be set to I2C mode automatically. */ err = I2C_Control( m_hCard, I2C_Port_A, I2C_ENABLE, /*Operation item*/ 1 /*Enable opertion item*/ ); if(err!=NoError) { strTemp.Format( TEXT("I2C_Control() Error = %d"), err); AfxMessageBox( strTemp ); return TRUE; } return TRUE; // return TRUE unless you set the focus to a control } void C7350IntDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void C7350IntDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this function to obtain the cursor to display while the user drags // the minimized window. HCURSOR C7350IntDlg::OnQueryDragIcon() { return static_cast(m_hIcon); } void C7350IntDlg::OnDestroy() { CDialog::OnDestroy(); // TODO: Add your message handler code here /*Disable I2C*/ I2C_Control( m_hCard, I2C_Port_A, I2C_ENABLE, /*Opertion item*/ 0 /*Disble opertion item*/ ); } void C7350IntDlg::OnStart() { // TODO: Add your control notification handler code here CString strTemp; U32 dwReadData; U32 dwWriteCmdAddr; U32 dwReadCmdAddr; U32 dwWriteData; I16 err; GetDlgItem( IDC_BT_START )->EnableWindow( FALSE ); for( m_dwOutVal = 0; m_dwOutVal < 0x100; m_dwOutVal++ ) { dwWriteCmdAddr = (m_dwOutVal&0xff); dwWriteData = (m_PatType == 0)? dwWriteCmdAddr:(255-dwWriteCmdAddr); err = I2C_Write( m_hCard, I2C_Port_A, (U16)m_dwI2CSlaveAddr, /*Slave device address*/ 1, /*Address byte count to be written*/ 1, /*Data byte count to be written*/ dwWriteCmdAddr, /*Cmd/Addr to be written*/ dwWriteData /*Data to be written*/ ); if(err<0) { strTemp.Format( TEXT("I2C_Write() Error = %d"), err); AfxMessageBox( strTemp ); return; } Sleep(50); //Wait for writing I2C EEPROM latency /*Read*/ dwReadCmdAddr = dwWriteCmdAddr; err = I2C_Read( m_hCard, I2C_Port_A, (U16)m_dwI2CSlaveAddr, /*Slave device address*/ 1, /*Address byte count to be read*/ 1, /*Data byte count to be read*/ dwReadCmdAddr, /*Cmd/Addr to be read*/ &dwReadData /*read Data*/ ); if(err<0) { strTemp.Format( TEXT("I2C_Read() Error = %d"), err); AfxMessageBox( strTemp ); return; } strTemp.Format( TEXT("Write Data = 0x%02X"), dwWriteData ); SetDlgItemText( IDC_STATIC_05, strTemp ); strTemp.Format( TEXT("Read Data = 0x%02X"), dwReadData ); SetDlgItemText( IDC_STATIC_06, strTemp ); } GetDlgItem( IDC_BT_START )->EnableWindow( TRUE ); } void C7350IntDlg::OnBnClickedRadioInc() { // TODO: Add your control notification handler code here m_PatType = 0; } void C7350IntDlg::OnBnClickedRadioDec() { // TODO: Add your control notification handler code here m_PatType = 1; }