diff --git a/src/SidePanel.tsx b/src/SidePanel.tsx index df004c2..8982590 100644 --- a/src/SidePanel.tsx +++ b/src/SidePanel.tsx @@ -5,7 +5,7 @@ */ import React, { useState } from 'react'; -import { useSelector } from 'react-redux'; +import { useDispatch, useSelector } from 'react-redux'; import { Button, CollapsibleGroup, @@ -16,15 +16,23 @@ import { import { NrfutilDeviceLib } from '@nordicsemiconductor/pc-nrfconnect-shared/nrfutil/device'; import ConfigDataPreview from './features/ConfigDataPreview/ConfigDataPreview'; -import { getConfigArray } from './features/Configuration/boardControllerConfigSlice'; +import { + getConfigArray, + getDefaultConfig, + setConfig, + setPmicConfig, +} from './features/Configuration/boardControllerConfigSlice'; export default () => { logger.debug('Rendering SidePanel'); const [isWriting, setWriting] = useState(false); + const dispatch = useDispatch(); + const device = useSelector(selectedDevice); const configData = useSelector(getConfigArray); + const defaultConfig = useSelector(getDefaultConfig); return ( @@ -50,6 +58,31 @@ export default () => { > Write config + diff --git a/src/app/DeviceSelector.tsx b/src/app/DeviceSelector.tsx index f86cf2b..5689515 100644 --- a/src/app/DeviceSelector.tsx +++ b/src/app/DeviceSelector.tsx @@ -19,6 +19,7 @@ import { import { clearConfig, + clearDefaultConfig, clearHardwareConfig, clearPmicConfig, setHardwareConfig, @@ -114,6 +115,7 @@ const onDeviceDeselected = (dispatch: AppDispatch) => () => { dispatch(clearConfig()); dispatch(clearPmicConfig()); dispatch(clearHardwareConfig()); + dispatch(clearDefaultConfig()); }; export default () => { diff --git a/src/features/Configuration/Configuration.tsx b/src/features/Configuration/Configuration.tsx index ad338bc..10e5a21 100644 --- a/src/features/Configuration/Configuration.tsx +++ b/src/features/Configuration/Configuration.tsx @@ -15,22 +15,19 @@ import { } from '@nordicsemiconductor/pc-nrfconnect-shared'; import BoardControllerConfigDefinition from '../../common/boards/BoardControllerConfigDefinition'; -import nrf54h20json from '../../common/boards/nrf_PCA10145_54H20.json'; -import nrf9161v091json from '../../common/boards/nrf_PCA10153_0.9.1_9161.json'; -import nrf9161v0100json from '../../common/boards/nrf_PCA10153_0.10.0_9161.json'; -import nrf54l15v020json from '../../common/boards/nrf_PCA10156_0.2.0.json'; -import nrf54l15v030json from '../../common/boards/nrf_PCA10156_0.3.0.json'; -import nrf9151v020json from '../../common/boards/nrf_PCA10171_0.2.0_9151.json'; import ConfigSlideSelector from '../ConfigSlideSelector/ConfigSlideSelector'; import ConfigSwitch from '../ConfigSwitch/ConfigSwitch'; import { getBoardRevisionSemver } from '../Device/deviceSlice'; import VCOMConfiguration from '../VCOMConfiguration/VCOMConfiguration'; import VoltageConfiguration from '../VoltageConfiguration/VoltageConfiguration'; import { + getDefaultConfig, getHardwareConfig, setConfig, + setDefaultConfig, setPmicConfig, } from './boardControllerConfigSlice'; +import { getBoardDefinition } from './boardDefinitions'; import { BoardConfiguration } from './hardwareConfiguration'; interface BoardControllerProps { @@ -38,17 +35,6 @@ interface BoardControllerProps { } const BoardController = ({ active }: BoardControllerProps) => { - const typednrf9161json = - nrf9161v0100json as BoardControllerConfigDefinition; - const typednrf9161v091 = nrf9161v091json as BoardControllerConfigDefinition; - const typednrf54l15v020json = - nrf54l15v020json as BoardControllerConfigDefinition; - const typednrf54l15v030json = - nrf54l15v030json as BoardControllerConfigDefinition; - const typednrf54h20json = nrf54h20json as BoardControllerConfigDefinition; - const typednrf9151v020json = - nrf9151v020json as BoardControllerConfigDefinition; - const dispatch = useDispatch(); useEffect(() => { @@ -65,74 +51,36 @@ const BoardController = ({ active }: BoardControllerProps) => { const device: Device | undefined = useSelector(selectedDevice); const boardRevision = useSelector(getBoardRevisionSemver); const hardwareConfig = useSelector(getHardwareConfig); + const defaultConfig = useSelector(getDefaultConfig); if (device) { logDeviceVersion(device, boardRevision); - switch (device?.devkit?.boardVersion) { - case 'PCA10156': - // nRF54L15 - if (boardRevision === '0.3.0') { - setInitialConfig( - dispatch, - hardwareConfig, - typednrf54l15v030json - ); - return BuildGui(typednrf54l15v030json); - } + const definition = getBoardDefinition(device, boardRevision); - // Default is revision 0.2.0 or 0.2.1 - setInitialConfig( + if (definition.boardControllerConfigDefinition) { + if (!defaultConfig.pins && !defaultConfig.pmicPorts) { + loadDefaultConfig( dispatch, - hardwareConfig, - typednrf54l15v020json + definition.boardControllerConfigDefinition ); - return BuildGui(typednrf54l15v020json); - - case 'PCA10153': - // nRF9161 - if (boardRevision === '0.10.0') { - setInitialConfig( - dispatch, - hardwareConfig, - typednrf9161json - ); - return BuildGui(typednrf9161json); - } - if (boardRevision === '0.9.0' || boardRevision === '0.9.1') { - setInitialConfig( - dispatch, - hardwareConfig, - typednrf9161v091 - ); - return BuildGui(typednrf9161v091); - } - if (!boardRevision) { - return Spinner(); - } - - return UnrecognizedBoardRevision(); - - case 'PCA10145': - // nRF54H20 - setInitialConfig(dispatch, hardwareConfig, typednrf54h20json); - return BuildGui(typednrf54h20json); + } + setInitialConfig(dispatch, hardwareConfig, defaultConfig); + return BuildGui(definition.boardControllerConfigDefinition); + } - case 'PCA10171': - // nRF9151 - setInitialConfig( - dispatch, - hardwareConfig, - typednrf9151v020json - ); - return BuildGui(typednrf9151v020json); + if (definition.controlFlag?.noRevision) { + return Spinner(); + } - default: - return UnrecognizedBoard(); + if (definition.controlFlag?.unknownRevision) { + return UnrecognizedBoardRevision(); } - } else { - return NoBoardSelected(); + + return UnrecognizedBoard(); } + + return NoBoardSelected(); }; const NoBoardSelected = () => ( @@ -149,7 +97,16 @@ const NoBoardSelected = () => ( target="_blank" rel="noreferrer" > - nRF9161DK (Rev. 0.9.0 and later) + nRF9161-DK (Rev. 0.9.0 and later) + + +
  • + + nRF9151-DK
  • @@ -172,7 +129,7 @@ const UnrecognizedBoardRevision = () => (

    This revision of the development kit is not supported. Update to the - latest version of nRF Connect Board Configurator // FIXME + latest version of nRF Connect Board Configurator

    ); @@ -247,13 +204,13 @@ const BuildGui = (boardJson: BoardControllerConfigDefinition) => { ); }; -function setInitialConfig( +function loadDefaultConfig( dispatch: AppDispatch, - hardwareConfig: BoardConfiguration, boardJson: BoardControllerConfigDefinition ) { if (!boardJson?.defaults) { logger.warn('No defaults found in board definition JSON'); + return; } // Create defaults map @@ -267,14 +224,32 @@ function setInitialConfig( ]) ); + dispatch( + setDefaultConfig({ + defaultConfig: { + pins: defaultConfig, + pmicPorts: defaultPmicConfig, + }, + }) + ); +} + +function setInitialConfig( + dispatch: AppDispatch, + hardwareConfig: BoardConfiguration, + defaultBoardConfig: BoardConfiguration +) { + const { pins: defaultPinConfig, pmicPorts: defaultPmicConfig } = + defaultBoardConfig; + // Merge with currently read hardware config const mergedPinConfig = new Map([ - ...defaultConfig, + ...(defaultPinConfig || []), ...(hardwareConfig.pins || []), ]); const mergedPmicConfig = new Map([ - ...defaultPmicConfig, + ...(defaultPmicConfig || []), ...(hardwareConfig.pmicPorts || []), ]); diff --git a/src/features/Configuration/boardControllerConfigSlice.ts b/src/features/Configuration/boardControllerConfigSlice.ts index 6ebf562..e52be84 100644 --- a/src/features/Configuration/boardControllerConfigSlice.ts +++ b/src/features/Configuration/boardControllerConfigSlice.ts @@ -13,6 +13,7 @@ interface ConfigState { boardControllerConfigData: Map; pmicConfigData: Map; hardwareConfig: BoardConfiguration; + defaultConfig: BoardConfiguration; } // nRF54H20 default config @@ -21,6 +22,7 @@ const initialState: ConfigState = { // This might be needed pmicConfigData: new Map([[1, 1800]]), pmicConfigData: new Map([]), hardwareConfig: {}, + defaultConfig: {}, }; const boardControllerConfigSlice = createSlice({ @@ -81,6 +83,18 @@ const boardControllerConfigSlice = createSlice({ clearHardwareConfig(state) { state.hardwareConfig = {}; }, + setDefaultConfig( + state, + { + payload: { defaultConfig }, + }: PayloadAction<{ defaultConfig: BoardConfiguration }> + ) { + state.defaultConfig = defaultConfig; + }, + + clearDefaultConfig(state) { + state.defaultConfig = {}; + }, }, }); @@ -105,6 +119,9 @@ export const getPmicConfigData = (state: RootState) => export const getHardwareConfig = (state: RootState) => state.app.boardControllerConfig.hardwareConfig; +export const getDefaultConfig = (state: RootState) => + state.app.boardControllerConfig.defaultConfig; + export const getConfigArray = createSelector( [getConfigData, getPmicConfigData], (configData: Map, pmicConfigData: Map) => [ @@ -135,6 +152,8 @@ export const { clearPmicConfig, setHardwareConfig, clearHardwareConfig, + setDefaultConfig, + clearDefaultConfig, } = boardControllerConfigSlice.actions; export default boardControllerConfigSlice; diff --git a/src/features/Configuration/boardDefinitions.ts b/src/features/Configuration/boardDefinitions.ts new file mode 100644 index 0000000..2e3a5ec --- /dev/null +++ b/src/features/Configuration/boardDefinitions.ts @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause + */ + +import { Device } from '@nordicsemiconductor/pc-nrfconnect-shared'; + +import BoardControllerConfigDefinition from '../../common/boards/BoardControllerConfigDefinition'; +import nrf54h20json from '../../common/boards/nrf_PCA10145_54H20.json'; +import nrf9161v091json from '../../common/boards/nrf_PCA10153_0.9.1_9161.json'; +import nrf9161v0100json from '../../common/boards/nrf_PCA10153_0.10.0_9161.json'; +import nrf54l15v020json from '../../common/boards/nrf_PCA10156_0.2.0.json'; +import nrf54l15v030json from '../../common/boards/nrf_PCA10156_0.3.0.json'; +import nrf9151v020json from '../../common/boards/nrf_PCA10171_0.2.0_9151.json'; + +export type BoardDefinition = { + boardControllerConfigDefinition?: BoardControllerConfigDefinition; + controlFlag?: { + unrecognizedBoard?: boolean; + unknownRevision?: boolean; + noRevision?: boolean; + }; +}; + +const typednrf9161json = nrf9161v0100json as BoardControllerConfigDefinition; +const typednrf9161v091 = nrf9161v091json as BoardControllerConfigDefinition; +const typednrf54l15v020json = + nrf54l15v020json as BoardControllerConfigDefinition; +const typednrf54l15v030json = + nrf54l15v030json as BoardControllerConfigDefinition; +const typednrf54h20json = nrf54h20json as BoardControllerConfigDefinition; +const typednrf9151v020json = nrf9151v020json as BoardControllerConfigDefinition; + +export function getBoardDefinition( + device: Device, + boardRevision: string | undefined +): BoardDefinition { + switch (device?.devkit?.boardVersion) { + case 'PCA10156': + // nRF54L15 + if (boardRevision === '0.3.0') { + return { + boardControllerConfigDefinition: typednrf54l15v030json, + }; + } + + // Default is revision 0.2.0 or 0.2.1 + return { boardControllerConfigDefinition: typednrf54l15v020json }; + + case 'PCA10153': + // nRF9161 + if (boardRevision === '0.10.0') { + return { boardControllerConfigDefinition: typednrf9161json }; + } + if (boardRevision === '0.9.0' || boardRevision === '0.9.1') { + return { boardControllerConfigDefinition: typednrf9161v091 }; + } + + if (!boardRevision) { + return { controlFlag: { noRevision: true } }; + } + + // return UnrecognizedBoardRevision(); + return { controlFlag: { unknownRevision: true } }; + + case 'PCA10145': + // nRF54H20 + return { boardControllerConfigDefinition: typednrf54h20json }; + + case 'PCA10171': + // nRF9151 + return { boardControllerConfigDefinition: typednrf9151v020json }; + + default: + return { controlFlag: { unrecognizedBoard: true } }; + } +}