-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial work to get I2C digipot control working (#2)
- Loading branch information
Showing
10 changed files
with
446 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* Digital Voice Modem - DSP Firmware | ||
* GPLv2 Open Source. Use is subject to license terms. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* @package DVM / DSP Firmware | ||
* | ||
*/ | ||
// | ||
// Based on code from Mark Carter (https://mcturra2000.wordpress.com/2022/03/10/sending-data-over-i2c-using-bit-banging/) | ||
// And also https://github.com/PascalPolygon/stm32_bitbang_i2c/ | ||
// Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0) | ||
// | ||
/* | ||
* Copyright (C) 2023 by Patrick McDonnell, W3AXL | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Library General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Library General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Library General Public | ||
* License along with this library; if not, write to the | ||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, | ||
* Boston, MA 02110-1301, USA. | ||
* | ||
*/ | ||
|
||
#include "DWT_delay.h" | ||
|
||
RCC_ClocksTypeDef RCC_Clocks; | ||
uint32_t HCLK_Freq; | ||
|
||
/** | ||
* @brief Initializes DWT_Clock_Cycle_Count for DWT_Delay_us function | ||
* @return Error DWT counter | ||
* 1: clock cycle counter not started | ||
* 0: clock cycle counter works | ||
*/ | ||
uint32_t DWT_Delay_Init(void) { | ||
// Get HCLK for calculation (done here so we don't have to do it every time) | ||
RCC_GetClocksFreq(&RCC_Clocks); | ||
HCLK_Freq = RCC_Clocks.HCLK_Frequency; | ||
/* Disable TRC */ | ||
CoreDebug->DEMCR &= ~CoreDebug_DEMCR_TRCENA_Msk; // ~0x01000000; | ||
/* Enable TRC */ | ||
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; // 0x01000000; | ||
|
||
/* Disable clock cycle counter */ | ||
DWT->CTRL &= ~DWT_CTRL_CYCCNTENA_Msk; //~0x00000001; | ||
/* Enable clock cycle counter */ | ||
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; //0x00000001; | ||
|
||
/* Reset the clock cycle counter value */ | ||
DWT->CYCCNT = 0; | ||
/* 3 NO OPERATION instructions */ | ||
__ASM volatile ("NOP"); | ||
__ASM volatile ("NOP"); | ||
__ASM volatile ("NOP"); | ||
|
||
/* Check if clock cycle counter has started */ | ||
if(DWT->CYCCNT) | ||
{ | ||
return 0; /*clock cycle counter started*/ | ||
} | ||
else | ||
{ | ||
return 1; /*clock cycle counter not started*/ | ||
} | ||
} | ||
|
||
/** | ||
* @brief This function provides a delay (in microseconds) | ||
* @param microseconds: delay in microseconds | ||
*/ | ||
void DWT_Delay_us(volatile uint32_t microseconds) | ||
{ | ||
uint32_t clk_cycle_start = DWT->CYCCNT; | ||
|
||
/* Go to number of cycles for system */ | ||
microseconds *= (HCLK_Freq / 1000000); | ||
|
||
/* Delay till end */ | ||
while ((DWT->CYCCNT - clk_cycle_start) < microseconds); | ||
} | ||
|
||
/* Use DWT_Delay_Init (); and DWT_Delay_us (microseconds) in the main */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Digital Voice Modem - DSP Firmware | ||
* GPLv2 Open Source. Use is subject to license terms. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* @package DVM / DSP Firmware | ||
* | ||
*/ | ||
// | ||
// Based on code from Mark Carter (https://mcturra2000.wordpress.com/2022/03/10/sending-data-over-i2c-using-bit-banging/) | ||
// And also https://github.com/PascalPolygon/stm32_bitbang_i2c/ | ||
// Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0) | ||
// | ||
/* | ||
* Copyright (C) 2023 by Patrick McDonnell, W3AXL | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Library General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Library General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Library General Public | ||
* License along with this library; if not, write to the | ||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, | ||
* Boston, MA 02110-1301, USA. | ||
* | ||
*/ | ||
|
||
#ifndef __DWT_DELAY_H__ | ||
#define __DWT_DELAY_H__ | ||
|
||
#include "stm32f4xx_rcc.h" | ||
|
||
uint32_t DWT_Delay_Init(void); | ||
void DWT_Delay_us(volatile uint32_t microseconds); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.